跳到内容

此函数创建一个新图,通过将多个顶点合并为一个。新图中的顶点对应于输入图中的顶点集。

用法

contract(graph, mapping, vertex.attr.comb = igraph_opt("vertex.attr.comb"))

参数

graph

输入图,可以是定向图或无向图。

mapping

一个数值向量,用于指定映射关系。其元素对应于顶点,并且对于每个元素,都给出了新图中的 ID。

vertex.attr.comb

指定如何在新的图中组合顶点属性。请参阅attribute.combination()以获取详细信息。

一个新的图对象。

详细信息

图的属性将被保留。图和边的属性保持不变,顶点属性根据vertex.attr.comb参数进行组合。

作者

Gabor Csardi csardi.gabor@gmail.com

contract_vertices().

示例


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