此函数创建一个新图,通过将多个顶点合并为一个。新图中的顶点对应于输入图中的顶点集。
用法
contract(graph, mapping, vertex.attr.comb = igraph_opt("vertex.attr.comb"))
参数
- graph
输入图,可以是定向图或无向图。
- mapping
一个数值向量,用于指定映射关系。其元素对应于顶点,并且对于每个元素,都给出了新图中的 ID。
- vertex.attr.comb
指定如何在新的图中组合顶点属性。请参阅
attribute.combination()
以获取详细信息。
参见
用于操作图结构的其他函数:+.igraph()
, add_edges()
, add_vertices()
, complementer()
, compose()
, connect()
, delete_edges()
, delete_vertices()
, difference()
, difference.igraph()
, disjoint_union()
, edge()
, igraph-minus
, intersection()
, intersection.igraph()
, path()
, permute()
, rep.igraph()
, reverse_edges()
, simplify()
, union()
, union.igraph()
, vertex()
作者
Gabor Csardi csardi.gabor@gmail.com
示例
g <- make_ring(10)
g$name <- "Ring"
V(g)$name <- letters[1:vcount(g)]
E(g)$weight <- runif(ecount(g))
g2 <- contract(g, rep(1:5, each = 2),
vertex.attr.comb = toString
)
## graph and edge attributes are kept, vertex attributes are
## combined using the 'toString' function.
print(g2, g = TRUE, v = TRUE, e = TRUE)
#> IGRAPH 5616e61 UNW- 5 10 -- Ring
#> + attr: name (g/c), mutual (g/l), circular (g/l), name (v/c), weight
#> | (e/n)
#> + edges from 5616e61 (vertex names):
#> [1] a, b--a, b a, b--c, d c, d--c, d c, d--e, f e, f--e, f e, f--g, h
#> [7] g, h--g, h g, h--i, j i, j--i, j a, b--i, j