问题
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