[R] matrix into vector with vertex names

joe j joe.stata at gmail.com
Fri Aug 5 10:40:25 CEST 2011


Using Igraph, I create shortest paths, then convert the matrix into
three column vectors - "vertex1", "vertex2", "shortestpath" - as the
code below shows.

#code for generating shortest path matrix and creating a 3 columns
from an igraph graph object "y"
y_s<-shortest.paths(y,  weights = NULL)
y_s <- melt(y_s)[melt(upper.tri(y_s))$value,] #Step 2: this is where
the trouble with memory occurs
y_s[,1] <- V(y)$name[y_s[,1]]
y_s[,2] <- V(y)$name[y_s[,2]]
names(y_s)<-c("vertex1", "vertex2", "shortestpath")

However I am looking for an alternative way of doing this becase at
the second step I run into a fight with my machine's memory. I know I
can create vectors using as.vector(), c(), etc, but I am not able to
create the two other columns with vertex names.

Best regards,
Joe.



More information about the R-help mailing list