3

If I have a list called List A:

[[1]]
  [1] 11.000000  1.500000  2.666667  2.833333 10.000000  1.500000

[[2]]
  [1]  1.50  1.00  3.25  3.75 10.50  1.50

[[3]]
  [1] 10.5  1.5  1.5  1.5  5.0  5.5

How can I unlist List A in R and get the output as per below:

         [,1]       [,2]      [,3]      [,4]     [,5]      [,6]
  [,1] 11.000000  1.500000  2.666667  2.833333 10.000000  1.500000
  [,2] 1.50       1.00      3.25      3.75     10.50      1.50
  [,3] 10.5       1.5       1.5       1.5      5.0        5.5

If I simply use unlist() it returns a vector

MBorg
  • 1,345
  • 2
  • 19
  • 38

3 Answers3

7

We can use do.call with rbind

do.call(rbind, A)
akrun
  • 874,273
  • 37
  • 540
  • 662
4

akrun's answer works well. An alternative method, which utilizes unlist(), is:

matrix(unlist(A), ncol=6, byrow=T)

This converts A into a vector, and then reorganizes it into a matrix with 6 columns, with the elements sorted by row.

MBorg
  • 1,345
  • 2
  • 19
  • 38
2

Also, invoke from purrr:

purrr::invoke(rbind, A)

invoke is just a wrapper around do.call.

tyluRp
  • 4,678
  • 2
  • 17
  • 36