Ordering cluster list by cluster size, R igraph -


i have network (g) thousands of clusters, can't seem figure out how order them size. looks membership attribute sorts clusters arbitrarily. example:

c <- clusters(g) c$membership gs <- induced.subgraph(g, c$membership==1) 

this indeed give me largest cluster, if try

gs <- induced.subgraph(g, c$membership==2) 

it doesn't give me second largest cluster, arbitrary cluster happens second in list.

is there way order c$membership according cluster size, i.e., 1 – largest, 2 – second largest, etc.?

you way:

# largest subgraph gs <- induced.subgraph(g, c$membership==order(-c$csize)[1]) # second largest subgraph gs <- induced.subgraph(g, c$membership==order(-c$csize)[2]) # etc... 

here's working example.

library(igraph)  g <- graph.full(5) %du% graph.full(4) %du% graph.full(3) set.seed(1)  # reproducible plots par(mar=c(0,0,0,0),mfrow=c(1,2)) plot(g) c <- clusters(g) gs <- induced.subgraph(g, c$membership==order(-c$csize)[1]) plot(gs) 


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -