[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] finding raw vertex index of a named vertex (R igraph)
From: |
Gábor Csárdi |
Subject: |
Re: [igraph] finding raw vertex index of a named vertex (R igraph) |
Date: |
Wed, 02 May 2018 16:46:37 +0000 |
I think the important thing here, is to vectorize the query, if you can do
that.
For a single vertex, I think
match('1001', vertex_attr(gt, "name"))
is as fast as this gets. igraph does not have a special index for vertex
names.
Gabor
On Wed, May 2, 2018 at 10:47 AM Dr Gregory Jefferis <
address@hidden> wrote:
> 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
> _______________________________________________
> igraph-help mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/igraph-help