Dr Gregory Jefferis
2018-05-02 09:46:55 UTC
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 want to do this a lot with some big graphs, so I would like to take
the most direct and efficient approach.
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
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
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
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
as.integer(V(gt)['1001'])
[1] 1I 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: microsecondsmicrobenchmark(as.integer(V(gt)['1001']))
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: microsecondsexpr 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
match(1001, names(V(gt)))
does not seem very elegant or particularly efficient, but strangely isthe 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