当我尝试创建下面的简单图表时,为什么会出现错误?如果我用数字替换“a”和“b”,那么它可以工作吗?任何解决方案
g1 <- graph(c("a","b"),directed=TRUE)
error is
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
From ?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”。
您可以使用以下内容将文本转换为适当的数字标识符:
g1 <- graph(as.numeric(factor(c("a","b"))), directed=TRUE)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)