本文介绍了igraph错误无法创建顶点数为负的空图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么在尝试创建下面的简单图形时会出现错误?如果我用数字替换"a"和"b",那么它有效吗?任何解决方案
Why do I get an error when I try to create below simple graph? If i replace "a" and "b" with numbers then it works? any solution
g1 <- graph(c("a","b"),directed=TRUE)错误是
Error in graph(c("a", "b"), directed = TRUE) : At type_indexededgelist.c:117 : cannot create empty graph with negative number of vertices, Invalid value In addition: Warning messages: 1: In graph(c("a", "b"), directed = TRUE) : NAs introduced by coercion 2: In graph(c("a", "b"), directed = TRUE) : NAs introduced by coercion推荐答案
在?graph中,您可以阅读:
edges: Numeric vector defining the edges, the first edge points from the first element to the second, the second edge from the third to the fourth, etc.由于它正在寻找数字矢量,但是您已经给它输入了文本,因此它将所有字母转换为NA(这是强制引入的NA".
Since it's looking for a numeric vector but you've given it text, it's converting all the letters to NA (this is the "NAs introduced by coercion."
您可以将文本转换为适当的数字标识符,例如:
You could convert the text to appropriate numeric identifiers with something like:
g1 <- graph(as.numeric(factor(c("a","b"))), directed=TRUE)更多推荐
igraph错误无法创建顶点数为负的空图
发布评论