0

I have a membership vector created with another software and I am stuck to write it into R so that I can use iGraph' modularity function to calculate modularity of this community division. 

Can someone help me with how to write the vector into R so that the Modularity(g,membership) could run?

I tried with using membership <- read.table(file), but the result could not be used with Modularity(g, membership)

Thanks,

Song

Song Chen
  • 15
  • 1
  • 5

1 Answers1

0

read.table creates a data frame, you need to convert that to a simple numeric vector. Alternatively you can use scan(). You might need to adjust the following to your data format.

library(igraph)
G <- graph.full(3) + graph.ring(3) + graph.full(3)

contents <- '1 1 1 2 2 2 3 3 3'
memb <- scan(textConnection(contents))
# Read 9 items

modularity(G, memb)
# [1] 0.6666667

Instead of the textConnection(), just put your file name there.

Gabor Csardi
  • 10,705
  • 1
  • 36
  • 53
  • Thanks, Gabor, I think this problem is now solved by using scan() function. Thank you very much. - Song – Song Chen Apr 11 '13 at 00:22