igraph-help
[Top][All Lists]

## Re: [igraph] reordering the vertex sequence

 From: Magnus Thor Torfason Subject: Re: [igraph] reordering the vertex sequence Date: Wed, 29 Jun 2011 09:24:41 -0400 User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11

```On 5/30/2011 23:03, Gábor Csárdi wrote:
```
```Dear Prof Freeman,

On Sat, May 28, 2011 at 10:12 AM, Lin Freeman<address@hidden>  wrote:
```
```How can I get the vertices into the order I want?
```
```
there are two possibilities. You can permute the vertices after
reading in the graph, with permute.vertices(). But it is much simpler
to use the (undocumented, sorry), 'predef' argument to read.graph(),
which can explicitly give the vertex names, in the right order:

G<- read.graph("zach.txt", format="ncol", weights=TRUE, names=TRUE,
predef=as.character(1:34))

Btw. please remember, that the numeric igraph vertex ids start with
zero in igraph 0.5.x, so they are not the same as the ids in your
graph.

Best,
Gabor
```
```
```
There's also a third possibility, which only requires a tiny bit more work, but does not depend on any undocumented interfaces (which is a
```plus for me):

> library(igraph)
> names(d.edges) <- c("V1","V2","weight")
> d.vertices     <- data.frame(vertices=1:34)
> g              <- graph.data.frame(d.edges, vertices=d.vertices)
> V(g)\$name
[1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10"
[11] "11" "12" "13" "14" "15" "16" "17" "18" "19" "20"
[21] "21" "22" "23" "24" "25" "26" "27" "28" "29" "30"
[31] "31" "32" "33" "34"
> E(g)\$weight
[1] 4 5 6 3 3 3 3 3 3 2 5 2 4 4 3 2 5 1 2 3 3 3 1 3 3 5
[27] 3 3 3 3 2 1 2 2 2 2 5 2 2 4 3 2 3 4 2 3 2 2 7 2 2 3
[53] 3 3 1 3 2 5 4 3 4 4 2 3 2 4 2 1 1 3 4 2 4 2 2 3 4 5

```
In other words, passing a separate data.frame with a list of vertices to graph.data.frame seems to ensure the desired ordering. I guess the fact that passing the vertices argument to graph.data.frame ensures correct ordering may not be documented but the functionality is the one I would intuitively have expected.
```
Best,
Magnus

```

reply via email to