如果这个问题看起来是多余的,我很抱歉,但是我开始为一个类使用R及其SNA工具,并且已经运行了几个不同的教程/实验室来适应。经常被推荐的资源是斯坦福的SNA实验室,但是即使只是运行入门实验室也会返回一些让我感到困惑的错误。带有注释的完整R代码可在这里获得:
http://sna.stanford.edu/lab.php?l=1
第一部分是相当直截了当的,我理解on.But中的大部分内容,一旦我尝试向图中添加顶点属性(第236行),我就会遇到我们刚刚创建的图形对象"krack_full“的问题。运行这个..。:
for (i in V(krack_full)) {
for (j in names(attributes)) {
krack_full <- set.vertex.attribute(krack_full,
j,
index = i,
attributes[i + 1, j])
}
}..。返回以下内容:
Error in set.vertex.attribute(krack_full, j, index = i, attributes[i + :
unused argument (index = i)所以我认为,好吧,使用他们概述的第二种方法,然后继续下去:
attributes = cbind(1:length(attributes[,1]), attributes)
krack_full <- graph.data.frame(d = krack_full_nonzero_edges,
+ vertices = attributes) 它似乎工作得很好,只是它确实创建了一个名为“(1:长度(属性,1)”的属性.
> summary(krack_full)
IGRAPH DN-- 21 232 --
attr: name (v/c), 1:length(attributes[, 1]) (v/n), AGE (v/n), TENURE (v/n), LEVEL (v/n), DEPT
(v/n), advice_tie (e/n), friendship_tie (e/n), reports_to_tie (e/n)所以一切都已经很奇怪了。最后,当我在下一步尝试获取顶点属性时,会遇到一些有关对象类的错误:
> get.vertex.attribute(krack_full, 'AGE')
Error in get.vertex.attribute(krack_full, "AGE") :
get.vertex.attribute requires an argument of class network.
> get.vertex.attribute(krack_full, 'TENURE')
Error in get.vertex.attribute(krack_full, "TENURE") :
get.vertex.attribute requires an argument of class network.
> get.vertex.attribute(krack_full, 'LEVEL')
Error in get.vertex.attribute(krack_full, "LEVEL") :
get.vertex.attribute requires an argument of class network.
> get.vertex.attribute(krack_full, 'DEPT')
Error in get.vertex.attribute(krack_full, "DEPT") :
get.vertex.attribute requires an argument of class network...。从现在起,几乎没有任何事情能像我想象的那样工作。因此,我怀疑导入数据的图形对象"krack_full“不知何故不应该是.?
再次,如果这是我犯的一个完全的新手错误,我很抱歉,但是如果你能给我指明正确的方向,我会非常感激。我想更好地了解这是怎么回事。
非常感谢。
发布于 2013-07-08 16:06:11
我强烈怀疑您试图遵循的教程是为iGraphVersion0.5.4或更早版本开发的。在那个时候,igraph对象中的顶点和边被索引为零而不是1,从本教程中的以下评论判断,本教程似乎解释了这一点:
# IMPORTANT NOTE: Unlike in most languages, R objects are numbered
# from 1 instead of 0, so if you want the first element in a
# vector, you would reference it by vector_name[1]. HOWEVER,
# igraph objects are numbered starting from 0. This can lead to
# lots of confusion, since it's not always obvious at first which
# objects are native to R and which belong to igraph.因为iGraph0.6,这不再是真实的;与其他所有行为良好的R对象一样,igraph接口中的顶点和边都是从1索引的。这里有两个选项(除了要求本教程的作者为iGraph0.6更新它之外):
igraph0包而不是igraph。igraph0包与igraph是完全相同的,但是使用基于零的索引来确保旧的ensure代码在过渡期间仍然可以使用。但是,您应该继续在新的分析项目中使用igraph。发布于 2015-12-23 16:54:48
对于函数
get.vertex.attribute 尝试新功能
vertex_attr 相反,
https://stackoverflow.com/questions/17520799
复制相似问题