边缘列表:
el <- rbind(c(6,11), c(1,8), c(8,12), c(11,17),
c(6,7), c(7,11), c(18,19), c(6,16))
在这种情况下,6,11,17,7,16连接,1,8,2连接和18,19相互连接。所以有三组。如何使用R?
从此边缘列表中获取这些组答案 0 :(得分:0)
您正在寻找连接的组件:http://en.wikipedia.org/wiki/Connected_component_(graph_theory)这在igraph中被称为clusters
(有点令人困惑)。获取社区列表相对复杂:
library(igraph)
g <- graph.data.frame(data.frame(el))
clu <- clusters(g)
comp <- tapply(seq_along(clu$membership), clu$membership, simplify = FALSE, function(x) x)
lapply(comp, function(x) V(g)$name[x])
# $`1`
# [1] "6" "11" "7" "17" "16"
#
# $`2`
# [1] "1" "8" "12"
#
# $`3`
# [1] "18" "19"