Search code examples
rgraphsocial-networkingigraph

How do I apply a function to each connected components within a graph/network?


I have a large igraph object 70,000+ vertices (nodes) and 200,000+ edges (connections). I'd like to calculate some measures of centrality but the network is too big. I thought a good work around would be to break my network into connected components (even the largest isn't too big).

I was thinking about using the igraph function clusters or related methods. Could I then calculate alpha.centrality() and bonpow() on the clusters? and then merge the results back into the original igraph object? (or a dataframe with all vertices)

I'm not sure of the best approach and I'd be really interested to hear any ideas people have. Many thanks :)


Solution

  • You can use the decompose.graph function in igraph to obtain a list of the connected components, then use lapply to run your function (alpha.centrality or bonpow) on each of the components. After having run decompose.graph, you may want to deallocate your original graph to re-claim some memory.