将大型列表转换为数据框的快速方式 [英] Fast way of converting large list to dataframe
问题描述
我正在寻找一种将列表转换为数据框的有效方式,以下列方式(这只是一个模拟示例):
lst < - list(a = c(1,2,3),b = c(4,5,6),c = c(7,8,9))
我正在寻找的最终结果是:
#[,1] [,2] [,3]
#a 1 2 3
#b 4 5 6
#c 7 8 9
这是我尝试过的,但不按我的意愿工作:
library(data.table)
result = rbindlist(Map(as.data.frame,lst))
任何建议?请记住,我的真实例子有很大的维度,我需要一个相当有效的方法来执行此操作。
非常感谢!
尝试这个。我们假设 L
的组件都具有相同的长度, n
,我们也假设没有行名: / p>
L< - list(a = 1:4,b = 4:1)#test input
n< - length(L [[1]])
DF< - 结构(L,row.names = c(NA,-n),class =data.frame)
I have a huge list (700 elements), each element being a vector of length = 16,000. I am looking for an efficient way of converting the list to a dataframe, in the following fashion (this is just a mock example):
lst <- list(a = c(1,2,3), b = c(4,5,6), c = c(7,8,9))
The end result I am looking for is:
# [,1] [,2] [,3]
#a 1 2 3
#b 4 5 6
#c 7 8 9
This is what I have tried, but isn't working as I wish:
library(data.table)
result = rbindlist(Map(as.data.frame, lst))
Any suggestion? Please keep in mind that my real example has huge dimensions, and I would need a rather efficient way of doing this operation.
Thank you very much!
Try this. We assume the components of L
all are of the same length, n
, and we also assume no row names:
L <- list(a = 1:4, b = 4:1) # test input
n <- length(L[[1]])
DF <- structure(L, row.names = c(NA, -n), class = "data.frame")
这篇关于将大型列表转换为数据框的快速方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!