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
We can use do.call with rbind
do.call(rbind, A)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With