1
votes

I have very basic issue with igraph (in R): renaming of the node ids.

For example, I have following graph in form of 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. Then, I used the following command to dump the local CC for each node.

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

"","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 ? That is if 7 in the output file points to 100 or 34 ? Is there anyway, we can force igraph to dump actual nodeids like 10, 34, 100 etc and their respective Local CC ?

I was googling and found people suggested "V(g)$name <- as.character(V(g))" for preserving the 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.

P.s: Here I noticed a similar question has been asked. 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.

1
It would be easier to help you if you provided a proper reproducible example with code we can copy/paste into R to test. Show exactly how you are creating the graph object.MrFlick
Edge list has been provided. I am using following code to read it DF <- read.csv("PATH OF EDGELIST.csv") g <- graph.DF(advice_data_frame) and above I provided example of how I am calculating Clustering coefficient (transitivity) and dumping it in the fileraj

1 Answers

3
votes

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")