3

I am trying to merge six graphs into a single graph, using the graph.union function in igraph.

Each graph is directed, named, and bipartite. Each graph has the following vertex and edge attributes:

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

However, when I merge the six graphs using `graph.union', it creates the following vertex and edge attributes:

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)

How do I ensure that the final graph object does not generate all these additional attributes?

Thanks,

Tim

timothyjgraham
  • 1,142
  • 1
  • 15
  • 28

2 Answers2

3

I don't think it's possible using graph.union (from the documentation: "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 a workaround you could extract the nodes and edges from your six graphs using as_data_frame(graph, what = "both"), merge/bind the data frames accordingly and then convert back using graph_from_data_frame. Not sure whether that's more work than deleting the extra graph attributes.

jac
  • 620
  • 4
  • 11
1

You can see my question and answer. I have added one new attribute to each igraph object only. Then graphs were unioned with the union() function and original values of attribute were restored.

Community
  • 1
  • 1
Nick
  • 1,086
  • 7
  • 21