igraph-help
[Top][All Lists]

## Re: [igraph] reordering the vertex sequence

 From: Gábor Csárdi Subject: Re: [igraph] reordering the vertex sequence Date: Mon, 30 May 2011 23:03:53 -0400

```Dear Prof Freeman,

On Sat, May 28, 2011 at 10:12 AM, Lin Freeman <address@hidden> wrote:
> Suppose I have a data set, "zach" in an ncol form with weights:
>
>                    2                   1                   4
>                    3                   1                   5
[...]
>
> I can read it into igraph as follows:
>
>> G <- read.graph("zach.txt", format="ncol", weights=V(G)\$weight
>
> But, then, the vertex sequence is:
>
>> V(G)
> Vertex sequence:
>  [1] "2"  "1"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10" "11" "12" "13" "14"
> "17"
> [16] "18" "20" "22" "26" "24" "25" "28" "29" "30" "27" "31" "32" "33" "15"
> "16"
> [31] "19" "21" "23" "34"
>
> However, I want the vertices in G to be arranged in the natural order
> according to their labels, "1"  "2"  etc.
> That way I can interpret the memberships produced by a community finding
> algorithm easily.
>
> 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

> Thank you,
>
> Lin Freeman
>
> --
> Linton C. Freeman
> Institute for Mathematical Behavioral Sciences and
> Department of Sociology
> School of Social Sciences  SSPA 2143
> University of California
> Irvine, CA 92697-5100
>
> Office:             (949) 824-6698
> Home (CA):      (949) 494-6139
>           (FL):      (941) 778-1074
> Secretary:        (949) 824-3663
> FAX:                (949) 824-3733
>
> _______________________________________________
> igraph-help mailing list
> https://lists.nongnu.org/mailman/listinfo/igraph-help
>
>

--
Gabor Csardi <address@hidden>     MTA KFKI RMKI

```

reply via email to