Natalia Pobedina
2012-Feb-11 23:56 UTC
[R] Using igraph: community membership of components built by decompose.graph()
Hi everyone! I would appreciate help with using decompose.graph(), community detection functions from igraph and lapply(). I have an igraph object G with vertex attribute "label" and edge attribute "weight". I want to calculate community memberships using different functions from igraph, for simplicity let it be "walktrap.community". This graph is not connected, that is why I decided to decompose it into connected components and run "walktrap.community" on each component, and afterwards add a community membership vertex attribute to the original graph G. I am doing currently the following comps <- decompose.graph(G,min.vertices=2) communities <- lapply(comps,walktrap.community) At this point I get stuck since I get the list object with the structure I cannot figure out. The documentation on "decompose.graph" tells only that it returns list object, and when I use "lapply" on the result I get completely confused in the results. Moreover, the communities are numbered from 0 in each component, and I don't know how to supply "weights" parameter into "walktrap.community" function. If it were not for the components, I would have done the following: wt <- walktrap.community(G, modularity=TRUE, weights=E(G)$weight) wmemb <- community.to.membership(G, wt$merges, steps=which.max(wt$modularity)-1) V(G)$"walktrap" <- wmemb$membership Could anyone please help me solve this issue? Or provide some information/links which could help? Thanks and best wishes, Natalia