简体   繁体   English

如何使用statnet / igraph创建同时具有边缘和隔离的网络

[英]How to create network with both edges and isolates using statnet/igraph

My question is similar to the one posted here: Network adding edges error 我的问题类似于此处发布的问题: 网络添加边缘错误

I am creating a network from scratches: I have data about 228 vertices, over a period of 13 years. 我正在从头开始创建一个网络:在13年的时间里,我有关于228个顶点的数据。 In the first year, I have just 1781 edges: they do not involve all of my vertices (barely 164), therefore the remaining nodes should result as isolated. 在第一年中,我只有1781条边:它们不涉及我的所有顶点(几乎不包含164个),因此其余结点应为孤立结点。

I created the network starting from my edgelist, using the code 我使用代码从边缘列表开始创建了网络

fdi.graph.2003 <- graph_from_data_frame(fdi.edge.2003, directed = T, vertices = fdi.attr.2003)

where fdi.edge.2003 is a data.frame containing edge attributes (including some potential weight columns): it only involves 164 vertices out of the total vertices defined by fdi.attr.2003 is a data.frame containing a row for each vertex that is involved in the edgelist (164 in total). 其中fdi.edge.2003是包含边属性(包括一些潜在的权重列)的data.frame:它仅涉及fdi.attr。定义的总顶点中的164个顶点。2003是data.frame,每个顶点包含一行包含在边缘列表中(共164个)。

all i get is a network with 164 vertices and no isolates. 我所得到的是一个具有164个顶点且没有孤立的网络。 However, I know they do exist in my data! 但是,我知道它们确实存在于我的数据中! Any suggestion on how to do it? 有什么建议吗? I think that I shoul initialize a network with all 228 vertices, adding their attributes and then adding the edges. 我认为我应该用所有228个顶点初始化一个网络,添加它们的属性,然后添加边。 However, nothing I am trying is working: rather, I am receiving the most disparate errors related to "Illegal vertex reference in addEdges_R". 但是,我正在尝试的任何方法都没有起作用:相反,我收到了与“ addEdges_R中的非法顶点引用”有关的最不相同的错误。

Any suggestion is more than welcome, also in the case it would involve the alternative package igraph, for which I am finding the same problem 任何建议都值得欢迎,在涉及替代方案igraph的情况下,我也发现了同样的问题

Filippo 菲利波

Use add.isolates from the sna package 使用sna包中的add.isolates

net1 = as.network(cbind(1:3, 3:5)) #5 vertices, 3 edges
net2 = as.network(add.isolates(net1, 10), matrix.type = "edgelist") #15 v, 3 e

And then you'll probably want to create new vertex names, eg 然后,您可能需要创建新的顶点名称,例如

net2%v%"vertex.names" = 1:15

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

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