0

I have this graph:

df<-data.frame(x=c('a','b','c'),y=c('d','c','f'))
g<-graph.data.frame(df,directed=F)

is there a way to return two lists of vertexes according to which subgraph they belong?

I'd like to get to this output:

 vertex id
1      a  1
2      d  1
3      b  2
4      c  2
5      f  2

Thank you

zunio
  • 1

1 Answers1

0

See clusters. Btw. what you are looking for is the components of the graph. (The igraph terminology is confusing, too.)

data.frame(vertex=V(g)$name, id=clusters(g)$membership)
#   vertex id
# 1      a  1
# 2      b  2
# 3      c  2
# 4      d  1
# 5      f  2
Gabor Csardi
  • 10,705
  • 1
  • 36
  • 53
  • Thank you.It's work. However, I try in this way: m<-multilevel.community (g) data.frame(vertex=m$names,id=m$membership) – zunio Apr 16 '14 at 16:35