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 !

4

1 回答 1

0

这已经快一年了,但我刚刚遇到了同样的问题并且很幸运地找到了解决方案。

问题是对于 statnet 包,edgelist 中的节点必须从 1 而不是 0 开始索引。因此,如果您将 1 添加到每个顶点标识符,它应该可以工作。下面的代码应该可以解决问题。

library(statnet)
dat <- read.csv('Slashdot081106_nosign.csv')
new_dat <- dat + 1
print(head(new_dat))
net <- as.network(new_dat, matrix.type="edgelist")
于 2020-03-03T07:58:09.463 回答