1

The following is a list with many many elements. Each elements is a dataframe. I want to combine all the dataframes to a dataframe.

[[1]]
     X1  X2  n
[1,] 13 156 12
[2,] 13 156 13
[3,] 13 156 14
[4,] 13 156 15

[[2]]
     X1  X2  n
[1,] 94 187 14
[2,] 94 187 15
[3,] 94 187 16

[[3]]
     X1  X2  n
[1,] 66 297 41
[2,] 66 297 42
[3,] 66 297 43
[4,] 66 297 44
[5,] 66 297 45
[6,] 66 297 46
[7,] 66 297 47
[8,] 66 297 48
     ...
     ...

How to combine all the elements of list to a dataframe which is as follows:

     X1  X2  n
[1,] 13 156 12
[2,] 13 156 13
[3,] 13 156 14
[4,] 13 156 15
[1,] 94 187 14
[2,] 94 187 15
[3,] 94 187 16
[1,] 66 297 41
[2,] 66 297 42
[3,] 66 297 43
[4,] 66 297 44
[5,] 66 297 45
[6,] 66 297 46
[7,] 66 297 47
[8,] 66 297 48
user2405694
  • 847
  • 2
  • 8
  • 19

2 Answers2

2

You can do it in base R as well, using function do.call. Below is the sample code.

dataList <- list()
dataList[[1]] <-  data.frame(x1=rnorm(10), x2 = rnorm(10), n=1:10)
dataList[[2]] <-  data.frame(x1=rnorm(10), x2 = rnorm(10), n=11:20)
dataList[[3]] <-  data.frame(x1=rnorm(10), x2 = rnorm(10), n=21:30)

dataSet <- do.call(rbind, dataList)
Kumar Manglam
  • 2,780
  • 1
  • 19
  • 28
1

You can easily combine the data.frames with

do.call(rbind, mylist)
Adam Quek
  • 6,973
  • 1
  • 17
  • 23