The intersection of two or more graphs are created. The graphs may have identical or overlapping vertex sets.

extract_intersection(..., byname = "auto", keep.all.vertices = TRUE)

Arguments

...

Graph objects or lists of graph objects. Allowed graph classes are igraph, network, matrix.

byname

A logical scalar, or the character scalar "auto". Whether to perform the operation based on symbolic vertex names. If it is "auto", that means TRUE if all graphs are named and FALSE otherwise. A warning is generated if "auto" and some (but not all) graphs are named.

keep.all.vertices

Logical, whether to keep vertices that only appear in a subset of the input graphs.

Value

a graph object of class igraph, network, or matrix.

Details

extract_intersection() extracts the intersection of two or more graphs. The graphs to be intersected can be of class igraph, network, or matrix. Only edges present in all graphs will be included.

If the byname argument is TRUE (or "auto" and all graphs are named), the operation is performed on symbolic vertex names instead of the internal numeric vertex ids.

extract_intersection() 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.

The name vertex attribute is treated specially if the operation is performed based on symbolic vertex names. In this case name must be present in all graphs, and it is not renamed in the result graph.

An error is generated if some input graphs are directed and others are undirected.

The actual intersection is performed through the intersection.igraph function, which also is the basis of the documentation of this function.

What extract_intersection() mainly adds is the opportunity to intersect graphs of different classes, not just of class igraph. In fact, the intrepid can even intersect graphs of different types together (although that will rarely be useful). The output will be a graph with the same class as that of the first graph passed to this function.

Examples

net1 <- snafun::create_manual_graph(
D - A:B:F:G, A - C - F - A, B - E - G - B, A - B, F - G,
H - F:G, H - I - J
)
net2 <- snafun::create_manual_graph(D - A:F:Y, B - A - X - F - H - Z, F - Y)
extract_intersection(net1, net2)
#> Error in eval(kall[[1]]): object 'net1' not found

g1 <- snafun::create_random_graph(10, "gnm", m = 15)
g2 <- snafun::create_random_graph(10, "gnm", m = 15)
extract_intersection(g1, g2)
#> Error in eval(kall[[1]]): object 'g1' not found

# intersection of three graphs
g3 <- snafun::create_random_graph(15, "gnm", m = 20)
extract_intersection(g1, g2, g3)
#> Error in eval(kall[[1]]): object 'g1' not found