简体   繁体   English

igraph R顶点ID得到改变

[英]igraph R vertex ids get changed

I have very basic issue with igraph (in R): renaming of the node ids. 我有一个非常基本的问题igraph(在R中):重命名节点ID。

For example, I have following graph in form of edgelist. 例如,我有一个edgelist形式的图表。

10,12
10,14
12,14
12,15
14,15
12,17
17,34
17,100
100,34

I want to calculate local clustering coefficient for each node. 我想计算每个节点的局部聚类系数。 First I have read the edgelist in object g using readcsv. 首先,我使用readcsv读取了对象g中的edgelist。 Then, I used the following command to dump the local CC for each node. 然后,我使用以下命令转储每个节点的本地CC。

write.csv(transitivity(g,type="local"),file="DumpLocalCC.csv")

Now the problem is, igraph changes the node IDs starting from 1 and I get following output 现在的问题是,igraph从1开始更改节点ID,我得到以下输出

"","x"
"1",NA
"2",0.333333333333333
"3",0.333333333333333
"4",0.333333333333333
"5",1
"6",1
"7",1

Now how can I resolute which node id is what ? 现在我该怎样才能确定哪个节点id是什么? That is if 7 in the output file points to 100 or 34 ? 也就是说,如果输出文件中的7指向100或34? Is there anyway, we can force igraph to dump actual nodeids like 10, 34, 100 etc and their respective Local CC ? 无论如何,我们可以强制igraph转储10,34,100等实际节点和它们各自的本地CC?

I was googling and found people suggested "V(g)$name <- as.character(V(g))" for preserving the nodeids. 我在谷歌搜索,发现人们建议“V(g)$ name < - as.character(V(g))”用于保留nodeids。 I tried however, I think I am not using it correctly. 然而,我试过,我想我没有正确使用它。 Also, since the data is large, I would not like to change the nodeids manually to make them sequential from 1 .... myself. 此外,由于数据很大,我不想手动更改节点数,使它们从1 ....我自己顺序。

Ps: Here I noticed a similar question has been asked. Ps:我在这里注意到一个类似的问题。 It has been suggested to "assign these numbers as vertex names". 有人建议“将这些数字指定为顶点名称”。 How to do that ? 怎么做 ? Can someone exemplify it please ? 有人可以举例说明吗?

Another similar question like this (I understand its the similar question), where it was suggested to open an issue. 这样的另一个类似问题(我理解它的类似问题),建议打开一个问题。 I am not sure if this has been resolved ? 我不确定这是否已经解决了?

Thanks in advance. 提前致谢。

You just need to combine the stats with the node names when you write the table. 您只需在编写表时将统计信息与节点名称组合在一起。 For example 例如

DF <- read.csv(text="10,12
    10,14
    12,14
    12,15
    14,15
    12,17
    17,34
    17,100
    100,34", header=FALSE)
g <- graph.data.frame(DF)
outdata <- data.frame(node=names(V(g)), trans=transitivity(g, type="local"))
write.csv(outdata, file="DumpLocalCC.csv")

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

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