igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] faster way to add attributes to nodes


From: Tamás Nepusz
Subject: Re: [igraph] faster way to add attributes to nodes
Date: Sat, 16 Feb 2013 22:50:15 +0100

> I have to attach node attributes which I have stored in a matrix like:
> 
> id       posts   threads   zindex
> "u32"  "123"   "12"        "0.45"
> 
> is there anything faster than this:
Yes, there is. First, construct an index vector where the i-th element denotes 
the index of the vertex whose attributes are stored in row i of your matrix:

names <- V(gTorgo)$name
indices <- sapply(torgoValues$id, function(x) which(names == x), 
USE.NAMES=FALSE)

Then simply assign the vertex attributes by subsetting V(gTorgo) with the 
indices vector:

V(gTorgo)[indices]$post <- as.numeric(torgoValues$posts)
V(gTorgo)[indices]$thread <- as.numeric(torgoValues$threads)
V(gTorgo)[indices]$zindex <- as.numeric(torgoValues$zindex)

-- 
T.


reply via email to

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