R igraph 手册页

如果您从 R 中使用 igraph,请使用此选项

contract {igraph}R 文档

将多个顶点收缩为一个顶点

描述

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

用法

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

参数

输入图,可以是定向的或非定向的。

mapping

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

vertex.attr.comb

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

详细信息

保留图的属性。图和边属性不变,顶点属性根据 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)


[包 igraph 版本 1.3.5 索引]