3

I'd like to rbind all a dataframes in ALIST - how would I do this?

alist <- list(a = data.frame(1:3),
              b = data.frame(4:6),
              a = data.frame(7:9))

(ALIST <- list(alist, alist, alist))
Kay
  • 2,702
  • 6
  • 32
  • 48
  • 2
    Lots of previous questions on this: http://stackoverflow.com/questions/1652522/rbind-dataframes-in-a-list-of-lists?rq=1 http://stackoverflow.com/questions/2851327/converting-a-list-of-data-frames-into-one-data-frame-in-r?lq=1 http://stackoverflow.com/questions/2209258/merge-several-data-frames-into-one-data-frame-with-a-loop/2209371 http://stackoverflow.com/questions/11934774/rbinding-a-list-of-lists-of-dataframes-based-on-nested-order?lq=1 – Thomas May 14 '13 at 10:05
  • None of these answered helped me. But admittetdly the `lapply(ALIST, function(x) x[["a"]])` should have come to my mind before... – Kay May 14 '13 at 11:48

1 Answers1

4

Use lapply to subset out the elements you want, and rbind with do.call on that list:

do.call("rbind",lapply(ALIST,function(x) x[["a"]]))
  X1.3
1    1
2    2
3    3
4    1
5    2
6    3
7    1
8    2
9    3
James
  • 65,548
  • 14
  • 155
  • 193