Hi,
you can iterate over the vertices, but it'll be probably slow. The
best solution is to create the graph directly from the data frame(s)
containing all structure and attribute data. See the
graph.data.frame() function for this.
Btw. it might be worth to post your igraph related questions to the
igraph-help mailing list if you don't get an answer here, (sadly) I am
not reading R-help frequently any more. See http://igraph.sf.net.
Best,
Gabor
On Mon, Apr 23, 2012 at 6:26 AM, cwdillon <cwdillon at gmail.com>
wrote:> Hi,
> So I've been figuring out how to use igraph in R and like it for
it's speed
> and simplicity. Now I have a graph built from an edgelist where vectors
have
> a $name attribute. ?I have another dataframe with attributes tied to a
> vector ID, which is the same as the $name attribute of vectors represented
> in the graph.
>
> How can I iterate over the graph by V(g)$name and do set.vector.attributes
> for the other attributes in the vector dataframe? ?Of course, the edgelist
> for the graph contains each vector zero or many times and they are not
> sorted in the same order as the vector dataframe. ?It's a large bit of
data:
> about 20m edges and 3m vectors. I can't do this by hand.
>
> Perhaps the answer is something like,
> by V(g)[]$name in g ?{
> ?i=get.index(V(g)$name)
> ?if (V(g)[1]$name == dataframe$ID) ?{
> ? ? V(g)[1]$newattribute1 <- dataframe$attribute1
> ? ? V(g)[1]$newattribute2 <- dataframe$attribute2
> ? ? V(g)[1]$newattribute3 <- dataframe$attribute3
> ? }
> }
>
> ?R,
> CW Dillon
>
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/Add-attributes-to-igraph-vector-by-name-not-index-tp4580032p4580032.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Gabor Csardi <csardi at rmki.kfki.hu>? ?? MTA KFKI RMKI