writing edgelist from igraph to file in R; how to write vertex names not vertex ids

1.2k views Asked by At

I have taken a graph, and pulled out a subgraph from it, using FlashGraphs, which gives me an igraph with vertex names spread out throughout the range of vertices. I attempt to write the edgelist using write.graph(sub.fg,"lc_edgelist.txt", "edgelist") but when I do so, I get a file that looks like this,

0 251
0 268
0 840
...

The file should look like

237 368616
237 374864
237 1197066
...

It seems that this just assigned vertex ids instead of using the names, so to check, I derived a list of vertexes from the main graph, where I just took all the vertexes with that id using the following command. lcc.v <- which(cc == lcc.id) I would just convert these vertexes by using the list of vertexes that I had also derived from the main graph, but from checking that reference, 368616 isn't the 251st vertex, it's 697. If it is possible to write the graph in terms of the vertex names assigned in the main graph, that would be the best solution, but anything that explains why the vertex numbers don't line up or a way to line them up would help as well.

1

There are 1 answers

0
Tamás On BEST ANSWER

Use write.graph(sub.fg, "lc_edgelist.txt", "ncol"). The NCOL format uses the symbolic vertex names from the $name vertex attribute instead of the node IDs. It is your responsibility to ensure the uniqueness of the names before saving.