igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] a question about importing graph object


From: Gábor Csárdi
Subject: Re: [igraph] a question about importing graph object
Date: Sun, 23 Sep 2012 16:37:49 -0400

Hi Niklas,

I am sorry, I am not sure what is your question here. Is your code too
slow? Does it give you unexpected/wrong results?

Gabor

On Thu, Sep 20, 2012 at 5:20 PM, Niklas Fischer
<address@hidden> wrote:
>
> Dear igraph list members,
>
> I'm newbie in  R and igraph, so I am not sure if I can import egocentric
> data
> : merging ego-alter, alter-ties together as indirected graph.
> There is an reproducible example which looks working.
> But I wonder if anything works with this logic because I did not find
> similar way importing egocentric data into R
>
>
> P.S sorry for second e-mail I found an error and fixed it.
> Regards,
> Niklas
>
> data<- data.frame(name=c("e1", "e2", "e3", "e4", "e5"),
>                      age=c(48,33,45,34,21),
>     gender=c("F","M","F","M","F"),
> # alter ids alters
>    alter.1=c("e1a1","e2a1","e3a1","e4a1","e5a1"),
>    alter.2=c("e1a2","e2a2","e3a2","e4a2","e5a2"),
>    alter.3=c("e1a3","e2a3","e3a3","e4a3","e5a3"),
> #ties between alters
> #alter1 and alter 2
>    tie.1=c(1,0,1,1,1),
> #alter1 and alter 3
>    tie.2=c(1,0,1,0,1),
> #alter2 and alter 3
>    tie.3=c(0,0,1,1,1))
>
> #### edge list between ego and alter
>
> data.long<-reshape(data,direction="long",
> varying=c(4,5,6),idvar="ego",timevar="TIME",v.names="alter")
> edgelist1<- data.long[,c(1,8)]
>
> ### edgelist between alter and alter
>
> data.2<-subset(data,data$tie.1 ==1)
> edgelista12<-data.frame(data.2$alter.1,data.2$alter.2)
> data.3<-subset(data,data$tie.2 ==1)
> edgelista13<-data.frame(data.3$alter.1,data.3$alter.3)
> data.4<-subset(data,data$tie.3 ==1)
> edgelista23<-data.frame(data.4$alter.2,data.4$alter.3)
>
> # merging the edgelists
> names(edgelist1)<-names(edgelista12)<- names(edgelista13)<-
> names(edgelista23)<-c("head","tail")
>
> edgelist<-rbind(edgelist1,edgelista12,edgelista13,edgelista23)
>
> # importing graph object
>
> library(igraph)
> g<-graph.data.frame(edgelist[,1:2],directed=FALSE)
> g
> IGRAPH UN-- 20 25 --
> attr: name (v/c)
>
>
>
>
>
>
>
> 2012/9/21 Niklas Fischer <address@hidden>
>>
>>
>> Dear igraph list members,
>>
>> I'm newbie in  R and igraph, so I am not sure if I can import egocentric
>> data
>> as below: merging ego-alter, alter-ties together as indirected graph.
>>
>> Appreciated if you let me know about whether anything wrong with this
>> logic.
>>
>> data<- data.frame(name=c("e1", "e2", "e3", "e4", "e5"),
>>                      age=c(48,33,45,34,21),
>>     gender=c("F","M","F","M","F"),
>> # alter ids alters
>>    alter.1=c("e1a1","e2a1","e3a1","e4a1","e5a1"),
>>    alter.2=c("e1a2","e2a2","e3a2","e4a2","e5a2"),
>>    alter.3=c("e1a3","e2a3","e3a3","e4a3","e5a3"),
>> #ties between alters
>> #alter1 and alter 2
>>    tie.1=c(1,0,1,1,1),
>> #alter1 and alter 3
>>    tie.2=c(1,0,1,0,1),
>> #alter2 and alter 3
>>    tie.3=c(0,0,1,1,1))
>>
>> #### edge list between ego and alter
>>
>> data.long<-reshape(data,direction="long",
>> varying=list(c(4,5,6)),
>> idvar="ego",timevar="TIME",v.names="alter"))
>> edgelist1<- data.long[,c(1,8)]
>>
>> ### edgelist between alter and alter
>>
>> data.2<-subset(data,data$tie.1 ==1)
>> edgelista12<-data.frame(data.2$alter.1,data.2$alter.2)
>> data.3<-subset(data,data$tie.2 ==1)
>> edgelista13<-data.frame(data.3$alter.1,data.3$alter.3)
>> data.4<-subset(data,data$tie.3 ==1)
>> edgelista23<-data.frame(data.4$alter.2,data.4$alter.3)
>>
>> # merging the edgelists
>> names(edgelist1)<-names(edgelista12)<- names(edgelista13)<-
>> names(edgelista23)<-c("head","tail")
>> edgelist<-rbind(edgelist1,edgelista12,edgelista13,edgelista23)
>>
>> # importing graph object
>>
>> library(igraph)
>> g<-graph.data.frame(edgelist[,1:2],directed=FALSE)
>> g
>> IGRAPH UN-- 20 25 --
>> attr: name (v/c)
>>
>> Niklas
>
>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/igraph-help
>



-- 
Gabor Csardi <address@hidden>     MTA KFKI RMKI



reply via email to

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