我使用结构命令将大型列表转换为数据帧(我在SO中阅读相关帖子):
l <- list()
l[[1]]<-c("2048","0","25","0","453826","65101","1503497087","1503497031","4_1R")
l[[2]]<-c("406","0","26","0","453826","65101","1503497087","1503497055","4_1R")
l[[3]]<-c("407","0","27","0","453826","65101","1503497087","1503497083","4_1R")
n <- length(l[[1]])
DF <- structure(l, row.names = c(NA, -n), class = "data.frame")
print(DF)
但是行排列成列。我可以使用转置数据框:
library(data.table)
DF <- transpose(DF)
哪个好,
但是&#34;结构&#34>中有任何选项。表示我想要一个行绑定&amp;行排序数据框?
答案 0 :(得分:0)
如果你取消列表,它会给你一个长向量,然后你可以把它放到一个矩阵中。将向量放在矩阵中时,指定byrow=TRUE
将导致行绑定。矩阵可以转换为数据帧。
> as.data.frame(matrix(unlist(l), nrow=3, byrow=TRUE))
V1 V2 V3 V4 V5 V6 V7 V8 V9
1 2048 0 25 0 453826 65101 1503497087 1503497031 4_1R
2 406 0 26 0 453826 65101 1503497087 1503497055 4_1R
3 407 0 27 0 453826 65101 1503497087 1503497083 4_1R