#Generate a sample network
g<-rgraph(10,tp=1.5/9)
#Extract some ego nets
g.in<-ego.extract(g,neighborhood="in")
g.out<-ego.extract(g,neighborhood="out")
g.comb<-ego.extract(g,neighborhood="in")
#View some networks
g.comb
#Compare ego net size with degree
all(sapply(g.in,NROW)==degree(g,cmode="indegree")+1) #TRUE
all(sapply(g.out,NROW)==degree(g,cmode="outdegree")+1) #TRUE
all(sapply(g.comb,NROW)==degree(g)/2+1) #Usually FALSE!
#Calculate egocentric network density
ego.size<-sapply(g.comb,NROW)
if(any(ego.size>2))
sapply(g.comb[ego.size>2],function(x){gden(x[-1,-1])})
Run the code above in your browser using DataLab