如何避免 igraph 中的图形联合名称冲突?

How to avoid graph union name clash in igraph?

我正在尝试使用 igraph 中的 graph.union 函数将六个图合并为一个图。

每个图都是有向的、命名的和二分的。每个图都有以下顶点和边属性:

name (v/c), type (v/c), label (v/c), id (v/c), edgeType (e/c), timestamp (e/c)

但是,当我使用“graph.union”合并六个图时,它会创建以下顶点和边属性:

attr: type_1 (v/c), type_2 (v/c), type_3 (v/c), type_4 (v/c), type_5 (v/c), type_6 (v/c), label_1 (v/c), label_2 (v/c), | label_3 (v/c), label_4 (v/c), label_5 (v/c), label_6 (v/c), id_1 (v/c), id_2 (v/c), id_3 (v/c), id_4 (v/c), id_5 (v/c), | id_6 (v/c), name (v/c), edgeType_1 (e/c), edgeType_2 (e/c), edgeType_3 (e/c), edgeType_4 (e/c), edgeType_5 (e/c), | edgeType_6 (e/c), timestamp_1 (e/c), timestamp_2 (e/c), timestamp_3 (e/c), timestamp_4 (e/c), timestamp_5 (e/c), | timestamp_6 (e/c)

如何确保最终图形对象不会生成所有这些附加属性?

谢谢,

蒂姆

我认为使用 graph.union 是不可能的(来自文档:"union keeps the attributes of all graphs. All graph, vertex and edge attributes are copied to the result. If an attribute is present in multiple graphs and would result a name clash, then this attribute is renamed by adding suffixes: _1, _2, etc.")。

作为解决方法,您可以使用 as_data_frame(graph, what = "both")、merge/bind 数据帧相应地从六个图形中提取节点和边,然后使用 graph_from_data_frame 转换回来。不确定这是否比删除额外的图表属性更有效。

你可以看到我的question and answer。我只为每个 igraph 对象添加了一个新属性。然后将图形与 union() 函数合并,并恢复属性的原始值。