timothyjgraham
timothyjgraham

Reputation: 1232

How to avoid graph union name clash in igraph?

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

Upvotes: 3

Views: 787

Answers (2)

Nick
Nick

Reputation: 1116

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.

Upvotes: 1

jac
jac

Reputation: 630

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.

Upvotes: 3

Related Questions