igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] finding raw vertex index of a named vertex (R igraph)


From: Dr Gregory Jefferis
Subject: [igraph] finding raw vertex index of a named vertex (R igraph)
Date: Wed, 02 May 2018 10:46:55 +0100

Hello,

In R igraph I want to find the raw vertex index from the vertex name

For example:

library(igraph)
gt=graph.tree(1000)
gt=set.vertex.attribute(gt, name = 'name', value = 1001:2000)

Now I want to find the integer vertex index of the vertex named 1001 (i.e. 1 in this toy example). One could do:

as.integer(V(gt)['1001'])
[1] 1

I want to do this a lot with some big graphs, so I would like to take the most direct and efficient approach.

library(microbenchmark)
 microbenchmark(as.integer(V(gt)['1001']))
Unit: microseconds
expr min lq mean median uq max neval as.integer(V(gt)["1001"]) 559.399 580.2445 640.5165 605.1565 663.3915 1044.307 100
microbenchmark(match(1001, names(V(gt))))
Unit: microseconds
expr min lq mean median uq max neval match(1001, names(V(gt))) 71.686 75.9195 86.37762 78.813 92.5785 221.455 100

Doing:

match(1001, names(V(gt)))

does not seem very elegant or particularly efficient, but strangely is the fastest approach that I have found so far.

Many thanks for any alternative suggestions,

Greg.

PS timings with CRAN igraph 1.1.2 on R 3.4.3 on macosx 10.12.6

--
Gregory Jefferis, PhD
Division of Neurobiology
MRC Laboratory of Molecular Biology
Francis Crick Avenue
Cambridge Biomedical Campus
Cambridge, CB2 OQH, UK

http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis
http://jefferislab.org
http://flybrain.stanford.edu



reply via email to

[Prev in Thread] Current Thread [Next in Thread]