我使用 fastgreedy.community 生成一个社区对象,其中包含 15 个社区。但是我怎样才能在这 15 个社区中提取最大的社区呢?
Community sizes
1 2 3 4 5 6 7 8 9 10 11 12 13 14
1862 1708 763 974 2321 1164 649 1046 2 2 2 2 2 2
15
2
在这个例子中,我想提取社区 5 以供进一步使用。
谢谢!
最佳答案
假设您的社区对象名为 community.object
, which(membership(community.object) == x)
提取社区中顶点的索引x
.如果你想要最大的社区,你可以设置x
至 which.max(sizes(community.object))
.最后,您可以使用 induced.subgraph
将该特定社区提取到单独的图表中:
> x <- which.max(sizes(community.object))
> subg <- induced.subgraph(graph, which(membership(community.object) == x))
关于R igraph : how to find the largest community?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15103744/