[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] add vertex attributes from a data.frame
From: |
Simone Gabbriellini |
Subject: |
Re: [igraph] add vertex attributes from a data.frame |
Date: |
Fri, 25 Mar 2011 16:55:21 +0100 |
Hi Gabor,
thank you very much, it seems to work on my data too|
best,
Simone
Il giorno 24/mar/2011, alle ore 21.27, Gábor Csárdi ha scritto:
> Hi Simone,
>
> On Thu, Mar 24, 2011 at 3:50 PM, Simone Gabbriellini <address@hidden> wrote:
>> Hello List,
>>
>> i am trying to add a vertex attribute from a data.frame like:
>>
>>>
>> who_invited_whom
>>
>> invited inviter
>> 1 user139 user83
>> 2 user140 user83
>> 3 user141 user83
>> 4 user142 user83
>> 5 user143 user83
>> 6 user144 user83
>>
>> I would like to add an attribute "invitedby" to vertex of type==0. I am
>> trying this:
>>
>> V(g)[type==0 & name %in%
>> who_invited_whom$invited]$invitedby<-who_invited_whom$inviter
>
> You get the warning because the number of vertices you select on the
> left hand side does not match the length of the right hand side.
>
> But anyway, I think this is wrong, because nothing ensures that the
> order of the vertices is the same on the left and right hand side. I
> think you want something like
>
> V(g)$invitedby <- as.character(NA)
> ord <- match(who_invited_whom$invited, V(g)$name[V(g)$type==0])
> V(g)$invitedby[V(g)$type==0][ord] <- as.character(who_invited_whom$inviter)
>
> I haven't tested it much, it seems to work for the toy data I just made up.
>
> Best,
> Gabor
>
>> Warning message:
>> In graph[[9]][[3]][[name]][index] <- value :
>> il numero di elementi da sostituire non `e un multiplo della lunghezza di
>> sostituzione
>>
>> Why am I getting the warning? Am I doing something wrong here?
>>
>> thanks for your help!
>>
>> best regards,
>> Simone
>> _______________________________________________
>> igraph-help mailing list
>> address@hidden
>> http://lists.nongnu.org/mailman/listinfo/igraph-help
>>
>
>
>
> --
> Gabor Csardi <address@hidden> MTA KFKI RMKI
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help