Here is an idea using t
, as.data.frame
, and map_dfr
from the purrr package.
L1 <- list(1:10, 5:14, 10:19)
library(purrr)
map_dfr(L1, ~as.data.frame(t(.x)))
# V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
# 1 1 2 3 4 5 6 7 8 9 10
# 2 5 6 7 8 9 10 11 12 13 14
# 3 10 11 12 13 14 15 16 17 18 19
The same idea but completely in base R.
do.call(rbind, lapply(L1, function(x) as.data.frame(t(x))))
# V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
# 1 1 2 3 4 5 6 7 8 9 10
# 2 5 6 7 8 9 10 11 12 13 14
# 3 10 11 12 13 14 15 16 17 18 19
Another base R idea that uses as.data.frame
twice. We can change the row names later.
as.data.frame(t(as.data.frame(L1)))
# V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
# X1.10 1 2 3 4 5 6 7 8 9 10
# X5.14 5 6 7 8 9 10 11 12 13 14
# X10.19 10 11 12 13 14 15 16 17 18 19
Finally, the same idea but use transpose
function from the data.table.
data.table::transpose(as.data.frame(L1))
# V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
# 1 1 2 3 4 5 6 7 8 9 10
# 2 5 6 7 8 9 10 11 12 13 14
# 3 10 11 12 13 14 15 16 17 18 19