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.