R igraph: how to find the largest community?

天涯浪子 提交于 2021-02-07 19:51:46

问题


I use fastgreedy.community to generate a community object, which contains 15 communities. But how can I extract the largest community among these 15 communities?

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 

In this example, I want to extract the community 5 for further use. Thanks!


回答1:


Assuming that your community object is named community.object, which(membership(community.object) == x) extracts the indices of the vertices in community x. If you want the largest, community, you can set x to which.max(sizes(community.object)). Finally, you can use induced.subgraph to extract that particular community into a separate graph:

> x <- which.max(sizes(community.object))
> subg <- induced.subgraph(graph, which(membership(community.object) == x))


来源:https://stackoverflow.com/questions/15103744/r-igraph-how-to-find-the-largest-community

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!