连接具有不同数量元素的嵌套列表
我是 R 的新手,有一个我无法解决的串联问题。
我有一个巨大的数据框,其形式为:
station POSIX date.str forec.time Lead.timemean.ens obs
6019 2011-08-06 06:00 20110806 00 006 45 67
6019 2011-08-06 07:00 20110806 00 007 69 72
6031 2011-08-06 12:00 20110806 06 006 87 95
6031 2011-08-06 13:00 20110806 06 007 88 97
我用过“ply”像这样分割数据框
mydata.split <- dlply(mydataframe, .(datestr), dlply, .(forec.time), dlply, .(lead.time), Identity, .drop = FALSE)
我做了一些用数据进行计算,这需要将数据以这种方式拆分。我将这个新列表称为 mynewlist af 计算。我想连接这些数据,但由于列表元素的数量不同,我遇到了问题。
<代码>>长度(mynewlist[[1]][[1]])
<代码>[1] 34
<代码>>长度(mynewlist[[1]][[2]])
<代码>[1] 38
我尝试使用 do.call( rbind, do.call( rbind, do .call( rbind, mynewlist) ) )
将列表连接到数据框中,但我收到以下消息:
In function (..., deparse.level = 1) : 结果的列数不是向量长度(arg 1)的倍数
有没有办法连接具有不同数量元素的嵌套列表?
我很高兴获得帮助或指明方向。 看待 西塞
I am a newbie to R and have a concatenation problem that I haven't been able to solve.
I have a huge data frame of the form:
station POSIX date.str forec.time lead.time mean.ens obs
6019 2011-08-06 06:00 20110806 00 006 45 67
6019 2011-08-06 07:00 20110806 00 007 69 72
6031 2011-08-06 12:00 20110806 06 006 87 95
6031 2011-08-06 13:00 20110806 06 007 88 97
I have use "ply" to split the data frame like this
mydata.split <- dlply(mydataframe, .(datestr), dlply, .(forec.time), dlply, .(lead.time), identity, .drop = FALSE)
I do some calculation with data, which require that data are split up this way. I call this new list mynewlist af calculations. I would like to concatenate these data, but I run into problems because of differing number of list elements.
> length(mynewlist[[1]][[1]])
[1] 34
> length(mynewlist[[1]][[2]])
[1] 38
I have tried to use do.call( rbind, do.call( rbind, do.call( rbind, mynewlist) ) )
to concatenate the list into a data frame, but I get the following message:
In function (..., deparse.level = 1) :
number of columns of result is not a multiple of vector length (arg 1)
Is there a way of concatenating a nested list with differing number of elements?
I am greateful for help or a point in a direction.
Regard
Sisse
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需使用 ldply 即可将所有这些列表重新拼接在一起。
使用
plyr
中的baseball
数据,按照问题中的方式使用dlply
吐出数据:现在使用
ldply
来将列表合并到一个data.frame
中:结果:
Just use
ldply
to stitch all those lists back together.With the
baseball
data inplyr
, usedlply
as in your question to spit the data:Now use
ldply
to combine the lists into adata.frame
:The results: