创建两个或多个图的并集。这些图可以具有相同或重叠的顶点集。
用法
# S3 method for class 'igraph'
union(..., byname = "auto")
详细信息
union()
创建两个或多个图的并集。 至少在一个图中包含的边将成为新图的一部分。 此函数也可以通过 %u%
运算符使用。
如果 byname
参数为 TRUE
(或 auto
且所有图都已命名),则该操作将基于符号顶点名称而不是内部数字顶点 ID 执行。
union()
保留所有图的属性。 所有图、顶点和边属性都将复制到结果。 如果属性存在于多个图中并且会导致名称冲突,则通过添加后缀来重命名此属性:_1、_2 等。
如果操作基于符号顶点名称执行,则 name
顶点属性将被特殊处理。 在这种情况下,name
必须存在于所有图中,并且不会在结果图中重命名。
如果某些输入图是有向的,而另一些是无向的,则会生成错误。
参见
其他用于操作图结构的函数:+.igraph()
, add_edges()
, add_vertices()
, complementer()
, compose()
, connect()
, contract()
, delete_edges()
, delete_vertices()
, difference()
, difference.igraph()
, disjoint_union()
, edge()
, igraph-minus
, intersection()
, intersection.igraph()
, path()
, permute()
, rep.igraph()
, reverse_edges()
, simplify()
, union()
, vertex()
作者
Gabor Csardi csardi.gabor@gmail.com
示例
## Union of two social networks with overlapping sets of actors
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 %u% net2)
#> IGRAPH 3c687e7 UN-- 13 21 --
#> + 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 3c687e7 (vertex names):
#> [1] I--J H--Z H--I G--H G--E F--X F--Y F--H F--C F--G B--E B--G A--X A--C A--F
#> [16] A--B D--Y D--G D--F D--B D--A