0

I have a csv file which has 2 columns, the first and second column contain nodes, each row means the nodes of an edge of an undirected graph. I am new to R, and this is my code:

library(statnet)
dat <- read.csv('Slashdot081106_nosign.csv')
print(head(dat))
net <- as.network(dat, matrix.type="edgelist")

and the console shows:

  from to
1    0  1
2    0  2
3    0  3
4    0  4
5    0  5
6    0  6
Error in add.edges.network(g, as.list(x[, 1]), as.list(x[, 2]), edge.check = edge.check) : 
  (edge check) Illegal vertex reference in addEdges_R.  Exiting.

I have searched a lot about this error info, however in vain. Who can tell me how to solve this problem ?

Thanks in advance !

Jun.W
  • 1
  • 1

1 Answers1

0

This is almost a year old at this point, but I just encountered this same problem and was lucky enough to find the solution.

The problem is that for the statnet package, the nodes in the edgelist must be indexed starting at 1 and not 0. So if you add 1 to every vertex identifier, it should work. The code below should do the trick.

library(statnet)
dat <- read.csv('Slashdot081106_nosign.csv')
new_dat <- dat + 1
print(head(new_dat))
net <- as.network(new_dat, matrix.type="edgelist")