简体   繁体   English

R: igraph, graph.data.frame 错误“边列表中的某些顶点名称未在顶点数据框中列出”

[英]R: igraph, graph.data.frame error “Some vertex names in edge list are not listed in vertex data frame”

I am attempting to assign attributes to the vertices in my network.我正在尝试为网络中的顶点分配属性。 The code I am using is:我使用的代码是:

g2 <- graph.data.frame(edgelist2014, vertices=nodelabels2014, directed=FALSE)

where edgelist2014 is an edgelist with 514,000+ observations in this format:其中 edgelist2014 是一个具有 514,000 多个观察值的边缘列表,采用以下格式:

fromRespondent  toRespondent   weight
1                2             6
1                3             4
...              ...           ...    
1014             1015          7

and nodelabels2014 is a data frame where the first column is fromRespondent and lists 1 - 1015 followed by 14 columns of attribute data. nodelabels2014是一个数据框,其中第一列fromRespondent并列出 1 - 1015 后跟 14 列属性数据。 I have also tried this with 1 - 1014.我也用 1 - 1014 试过这个。

I run the code in multiple different ways and keep getting the error:我以多种不同的方式运行代码并不断收到错误消息:

Some vertex names in edge list are not listed in vertex data frame. 

I know that all the observations match because I ran a merge function in Stata and every observation was matched from edgelist2014 and nodelabels2014 .我知道,所有的意见匹配,因为我跑在Stata合并功能,每观察从匹配edgelist2014nodelabels2014 Please let me know what I am doing wrong.请让我知道我做错了什么。

I have the same question which is not seemingly working for non-numeric data.我有同样的问题,它似乎不适用于非数字数据。 I want to produce an igraph showing linkages of actors.我想制作一个显示演员联系的 igraph。

nodes <- read.csv("D1-NODES.csv", header=T, as.is=T)
links <- read.csv("D1-EDGES.csv", header=T, as.is=T)

Data数据D1-EDGES.csvD1-节点.csv

# Producing the igraph

net <- graph_from_data_frame(d=links, vertices=nodes, directed=T)
#create a layout for plot
l <- layout_nicely(net2)
p1 <- plot(net2, edge.arrow.size= 0.5, edge.curved= 0.2, vertex.color=nodes$Inter.type, rescale=5, frame= T,vertex.label.cex=1.4, vertex.size=20, vertex.label.color="black",edge.lty= 2, vertex.frame.color= "gray", layout=l )

I get this error message:我收到此错误消息:

Some vertex names in edge list are not listed in vertex data frame边列表中的某些顶点名称未在顶点数据框中列出

I already had this problem and solved it by developing the following suggestions:我已经遇到了这个问题,并通过提出以下建议解决了这个问题:

Initially, try to insert non-numeric characters in your network's outgoing and incoming variables, respectively, what you call "fromRespondent" and "toRespondent".最初,尝试分别在网络的传出和传入变量中插入非数字字符,即您所说的“fromRespondent”和“toRespondent”。 Insert s01, s02, s03, ... instead of 1, 2, 3, ...插入 s01, s02, s03, ... 而不是 1, 2, 3, ...

If the error persists, check that your data sets "edgelist2014" and "nodelabels2014" are in agreement.如果错误仍然存​​在,请检查您的数据集“edgelist2014”和“nodelabels2014”是否一致。 For example, look at "nodelabels2014" for exactly all the corresponding vertices as edges formed in "edgelist2014".例如,查看“nodelabels2014”中的所有对应顶点作为“edgelist2014”中形成的边。

Since your "edgelist2014" dataset have about 514,000 examples, you will be more successful you implement the verification, for the "fromRespondent" and "toRespondent" columns, if that something that was missingand if exist each of these elements in "nodelabels2014" dataset.由于您的“edgelist2014”数据集有大约 514,000 个示例,因此您将更成功地对“fromRespondent”和“toRespondent”列进行验证,如果“nodelabels2014”数据集中的这些元素中的每一个都缺失并且存在的话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM