简体   繁体   English

将data.frames列表拆分为data.frames的子列表

[英]Split a list of data.frames into sublists of data.frames

I have a list of data.frames that looks like: 我有一个data.frames列表,看起来像:

List          
[[1]]                
    .....               
  List             
   [[2]]            
  ....           

 List              
[[95]]   

I would like to split this long list of data.frames in sublists of 3 data.frames each in order to do other computations in a simple and easy way. 我想在3个data.frames的子列表中分割这长长的data.frames列表,以便以简单方便的方式进行其他计算。

Something like: 就像是:

sublist1 <- List[1:3] sublist1 < - 列表[1:3]
sublist2 <- List[3:6] sublist2 < - 列表[3:6]
sublist3 <- List[6:9] sublist3 < - 列表[6:9]

and so on. 等等。

I would do something like this : 我会做这样的事情:

ll <- by(seq_along(l),cut(seq_along(l),3),
                 FUN=function(x)l[x])

Now I have , a list which contains 3 lists. 现在我有一个包含3个列表的列表。 For example to access first sub-lists, you can do : 例如,要访问第一个子列表,您可以执行以下操作:

ll[[1]]
[[1]]
data frame with 0 columns and 0 rows

[[2]]
data frame with 0 columns and 0 rows

[[3]]
data frame with 0 columns and 0 rows

And so on , ll[[2]]... 等等,ll [[2]] ......

You can use assign and do something like this: 您可以使用assign并执行以下操作:

d <- data.frame()
l <- list(d,d,d,d,d,d,d,d,d)

for(i in seq(1, length(l), by=3)) {
    assign(paste0("x", i), l[i:(i+2)])
}

> ls()
# [1] "d"  "i"  "l"  "x1" "x4" "x7"

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

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