[英]Row bind multiple dataframes contained in a list of lists
Is there a way to row bind multiple data frames contained in a list of lists with few lines of code and minimising memory use?有没有办法用几行代码行绑定包含在列表列表中的多个数据帧并最大限度地减少内存使用?
super_list
contains 20 sub lists, and each of those lists contains 100 data frames. super_list
包含 20 个子列表,每个列表包含 100 个数据框。
super_list[[a]][[i]]
can be concatenated with super_list[[b]][[j]]
only if j == m
.仅当j == m
super_list[[a]][[i]]
才能与super_list[[b]][[j]]
。
I want to create 100 data frames, each one is made from row binding 20 data frames, one from each sub list of super_list
.我想创建 100 个数据帧,每个数据帧由行绑定 20 个数据帧组成,一个来自super_list
每个子列表。
I'd like to avoid using a for loop to create 100 row binded dataframes, as this seems to require double the memory and seems inelegant.我想避免使用 for 循环来创建 100 行绑定数据帧,因为这似乎需要双倍的内存并且看起来不雅。 Is there a better way?有没有更好的办法?
To clarify further, the first data frame would be为了进一步澄清,第一个数据框将是
df[[1]] <- bind_rows(super_list[[1]][[1]], super_list[[2]][[1]], ..., super_list[[20]][[1]])
I found purrr does transpose, this is working for me我发现 purrr 确实转置了,这对我有用
library(purrr)
super_list <- super_list %>% purrr::transpose()
super_list <- lapply(super_list, bind_rows)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.