0

I am using igraph in R, and I have an edgelist (g) of about 9000+ interactions which occured within 78 groups. I used the decompose function to create a list of 78 individual igraphs (dg). I want to calculate the eigenvectors for each of the vectors within each igraph.

I can do this for each graph individually using

eigen_centrality(dg[[1]], directed = FALSE, scale = TRUE, weights = NULL)

However, doing all 78 graphs individually will be very time consuming and I would like to create a function or loop that will go through the list (dg) and do this for me. I'm afraid I haven't come close to writing a bit of code that will do this so I can't provide any examples of reproducible code.

Would anyone be able to suggest a solution that could do this? Each graph is under the name dg[[x]] x being 1 to 78.

Very grateful for any advice or suggestions.

1 Answers1

1

The lapply function should be able to handle this for you. You haven't given any example code, but this should get you started:

g=sample_gnp(1000,1/1000)
dg=decompose(g,min.vertices=2)

eigen.list=lapply(dg,eigen_centrality,directed=F,scale=T,weights=NULL)
lapply(eigen.list,"[[","vector")
Ryan Haunfelder
  • 766
  • 3
  • 11