graph.edgelist 错误

Error with graph.edgelist

您好,我一直在尝试使用 igraph 包将我的数据框转换为图形对象。

g = as.matrix(votings[,1:2])
g = graph.edgelist(votings, directed = TRUE)
Error in graph.edgelist(votings) :    graph_from_edgelist expects a matrix with two columns

我也试过 drop = FALSE,正如其他帖子所建议的那样。

g = graph.edgelist(votings[,1:2, drop = FALSE))
Error in graph.edgelist(votings) :    graph_from_edgelist expects a matrix with two columns

知道我的代码有什么问题吗?投票的前两列包含字符串(名称)。

所以我尝试了 graph_from_data_frame,结果正如 Gabor Casardi 所建议的那样有效。谢谢!但是如果你想使用 graph.edgelist,这个就可以了。

library(igraph)
g = graph_from_edgelist(as.matrix(votings[,1:2, drop = FALSE], directed = TRUE))