# R: how to export data frame with vertex name from ego\_extract?

**URL:** <https://igraph.discourse.group/t/r-how-to-export-data-frame-with-vertex-name-from-ego-extract/112>\
**Category:** Usage\
**Tags:** R\
**Created:** [26 February 2020 02:00 UTC](https://igraph.discourse.group/t/r-how-to-export-data-frame-with-vertex-name-from-ego-extract/112 "2020-02-26T02:00:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xuewen\_Yan](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/xuewen_yan/32/130_2.png) [@Xuewen\_Yan](https://igraph.discourse.group/u/Xuewen_Yan)\
**Post date:** [26 February 2020 02:00 UTC](https://igraph.discourse.group/t/r-how-to-export-data-frame-with-vertex-name-from-ego-extract/112/1 "2020-02-26T02:00:13Z")

</div>

I’ve followed through the example to create ego-size and alter-density measures. When I view the results in R console, I could see the ego-vertex as well as these attributes on the right column. However, when I try to use cbind or as.data.frame to output my result, I only have the ego-size and alter-density outcomes, _without the ego vertex_. When I check the # of columns of these results, it also shows up as 1 instead of 2 (as if the ego vertex column isn’t a real column).

Could anyone please indicate how I could extract ego-vertex info when I export my data? Thank you very much!

```r
#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])})

```

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [26 February 2020 07:33 UTC](https://igraph.discourse.group/t/r-how-to-export-data-frame-with-vertex-name-from-ego-extract/112/2 "2020-02-26T07:33:15Z")

</div>

It appears you are asking for help with the [`sna` package](https://www.rdocumentation.org/packages/sna/), but this is the forum for [igraph](http://igraph.org/), not for `sna`. Unfortunately, this makes the question off-topic. Perhaps you could try the [statnet user group](http://statnet.csde.washington.edu/statnet_users_group.shtml), where people will be much more familiar with `sna` than here.
