igraph错误无法创建顶点数为负的空图

编程入门 行业动态 更新时间:2024-10-28 11:27:42
本文介绍了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错误无法创建顶点数为负的空图

本文发布于:2023-07-18 08:26:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1142828.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:顶点   数为   错误   igraph

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!