18

I'm working with the iGraph library and I need to run some statistical analysis on the network. I'm computing several variables using iGraph and then want to use those indicators as the dependent variable in a few regressions and the vertex attributes as the independent variables in the model.

I'm able to load the data, run the igraph analysis, but I'm having trouble turning the igraph object back into a data frame. I don't really need the edges to be preserved, just each vertex to be turned into an observation with the attributes serving as a column in each row.

I tried the following:

fg <- fastgreedy.community(uncompg, merges=TRUE)
z<-which.max(fg$modularity)
fgc<- community.to.membership(uncompg, fg$merges,z)
names<-array(V(uncompg)$name)
fccommunity<-array(fgc$membership)
fcresult<-as.matrix(cbind(names,fccommunity))
compg <- set.vertex.attribute(compg, "community", value=fccommunity)

uncompg<-simplify(as.undirected(compg))
hubscore<-hub.score(compg)$vector
authscore<-authority.score(compg)$vector

netdata<-as.data.frame(compg)

But it throws the following error:

  cannot coerce class '"igraph"' into a data.frame

Any help or pointers?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
biased_estimator
  • 723
  • 3
  • 7
  • 13

1 Answers1

33

I am not quite sure what you are trying to do. Do you want the relationships as a data frame, or the node attribute as a data frame?

To do the former:

> compg.edges <- as.data.frame(get.edgelist(compg))

To do the latter:

> compg.df <- as.data.frame(list(Vertex=V(compg), Community=fccommunity, Hubscore=hubscore, Authscore=authscore), stringsAsFactors=FALSE)
DrewConway
  • 5,407
  • 7
  • 35
  • 32
  • I was actually trying to do the later, but the former is very useful as well. I'm trying to bring some computed net attributes back into the data frame to run some logit analysis on them. – biased_estimator Feb 06 '11 at 21:54