用igraph消除集团集群

时间:2018-12-05 18:18:32

标签: r cluster-analysis igraph

我有一个包含多个组件的网络,我想:

  1. 删除所有完全连接的群集

玩具示例:

g <- graph(c("a","b","b","c","c","a","f","g","h","g"))
result_g <- graph(c("f", "g","h","g"))
  1. 仅在(除其他条件外)这些顶点不属于完全连接的组件,才能仅标记组件的顶点。

1 个答案:

答案 0 :(得分:1)

为此,您可以先使用components函数将图形拆分为连接的组件。然后,您可以测试每个组件以查看它是否是完整的子图。当且仅当边的数量等于n(n-1)/ 2时,图才是满的,其中n是节点数。因此,使用您的示例:

CompList = components(g)
NotFull = c()
for(i in 1:CompList$no) {
    COMP = induced_subgraph(g, which(CompList$membership==i))
    VC = vcount(COMP)
    if(ecount(COMP) != VC*(VC-1)/2) {
        NotFull = c(NotFull, which(CompList$membership==i)) }
}
result_g = induced_subgraph(g, NotFull)
result_g
IGRAPH 5d61ea5 DN-- 3 2 -- 
+ attr: name (v/c)
+ edges from 5d61ea5 (vertex names):
[1] f->g h->g