The intersection of two or more graphs are created. The graphs may have identical or overlapping vertex sets.
Usage
# S3 method for igraph
intersection(..., byname = "auto", keep.all.vertices = TRUE)
Arguments
- ...
Graph objects or lists of graph objects.
- byname
A logical scalar, or the character scalar
auto
. Whether to perform the operation based on symbolic vertex names. If it isauto
, that meansTRUE
if all graphs are named andFALSE
otherwise. A warning is generated ifauto
and some (but not all) graphs are named.- keep.all.vertices
Logical scalar, whether to keep vertices that only appear in a subset of the input graphs.
Details
intersection()
creates the intersection of two or more graphs:
only edges present in all graphs will be included. The corresponding
operator is %s%
.
If the byname
argument is TRUE
(or auto
and all graphs
are named), then the operation is performed on symbolic vertex names instead
of the internal numeric vertex ids.
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.
See also
Other functions for manipulating graph structure:
+.igraph()
,
add_edges()
,
add_vertices()
,
complementer()
,
compose()
,
connect()
,
contract()
,
delete_edges()
,
delete_vertices()
,
difference()
,
difference.igraph()
,
disjoint_union()
,
edge()
,
igraph-minus
,
intersection()
,
path()
,
permute()
,
rep.igraph()
,
reverse_edges()
,
simplify()
,
union()
,
union.igraph()
,
vertex()
Author
Gabor Csardi csardi.gabor@gmail.com
Examples
## Common part of two social networks
net1 <- graph_from_literal(
D - A:B:F:G, A - C - F - A, B - E - G - B, A - B, F - G,
H - F:G, H - I - J
)
net2 <- graph_from_literal(D - A:F:Y, B - A - X - F - H - Z, F - Y)
print_all(net1 %s% net2)
#> IGRAPH 329886b UN-- 13 4 --
#> + attr: name (v/c)
#> + vertex attributes:
#> | name
#> | [1] D
#> | [2] A
#> | [3] B
#> | [4] F
#> | [5] G
#> | [6] C
#> | [7] E
#> | [8] H
#> | [9] I
#> | [10] J
#> | [11] Y
#> | [12] X
#> | [13] Z
#> + edges from 329886b (vertex names):
#> [1] F--H A--B D--F D--A