如果您从 R 中使用 igraph,请使用此选项
contract {igraph} | R 文档 |
此函数创建一个新图,方法是将多个顶点合并为一个顶点。新图中的顶点对应于输入图中的顶点集合。
contract(graph, mapping, vertex.attr.comb = igraph_opt("vertex.attr.comb"))
图 |
输入图,可以是定向的或非定向的。 |
mapping |
指定映射关系的数值向量。其元素对应于顶点,并且对于每个元素,都给出新图中的ID。 |
vertex.attr.comb |
指定如何在新图中组合顶点属性。请参阅 |
保留图的属性。图和边属性不变,顶点属性根据 vertex.attr.comb
参数组合。
一个新的图对象。
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)