简体   繁体   English

如何最有效地将行列表转换为R中的数据帧

[英]How to most efficiently convert list of rows to a data frame in R

To be more specific, I have a list whose elements are vectors which correspond to one row of a data frame. 更具体地说,我有一个列表,其元素是与数据帧的一行相对应的向量。

The method outline here: https://stackoverflow.com/a/12382764/2472107 这里的方法概述: https : //stackoverflow.com/a/12382764/2472107

is extremely efficient/fast but it only works for lists that contain vectors that correspond to columns in a data frame. 是非常高效/快速的方法,但仅适用于包含与数据帧中的列相对应的向量的列表。

I tried transposing the data frame afterwards, but this takes exceedingly long. 之后,我尝试转置数据帧,但这花费了非常长的时间。

Thanks! 谢谢!

From the context I gather that your elements are identical, say they are all doubles . 从上下文中我得知您的元素是相同的,说它们都是doubles If you want to transpose the data, it is much more efficient to put them in a matrix . 如果要转置数据,将它们放在matrix会更有效。 You can do this with matrix(unlist(x), ncol=length(x)) , where x is your list. 您可以使用matrix(unlist(x), ncol=length(x)) ,其中x是您的列表。

The code above also does the transpose. 上面的代码也进行转置。 If you want to keep it as is you could say matrix(unlist(x), nrow=length(x), byrow=TRUE) . 如果要保持原样,可以说matrix(unlist(x), nrow=length(x), byrow=TRUE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM