> 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. _______________________________________________ igraph-help mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/igraph-help
