简体   繁体   中英

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[[a]][[i]] can be concatenated with super_list[[b]][[j]] only if j == m .

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 .

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. 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

library(purrr)
super_list <- super_list %>% purrr::transpose()
super_list <- lapply(super_list, bind_rows)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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