igraph-help
[Top][All Lists]

## Re: [igraph] a question about importing graph object

 From: Niklas Fischer Subject: Re: [igraph] a question about importing graph object Date: Fri, 21 Sep 2012 00:20:09 +0300

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

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

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
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