简体   繁体   中英

Combining Lists of Multiple Dataframes in R

For simplicity, I have made the following code.

 df1 <- data.frame(A=c(1:3), B=c('A', 'A', 'A', 'B', 'B', 'B'))
 df2 <- data.frame(C=c('D'), D=c(4, 4, 5, 5, 6, 6))
 one <- split(df1, df1$B)
 two <- split(df2, df2$D)
 goal_df <- data.frame(A=c(1:3), B=c('A', 'A', 'A', 'B', 'B', 'B'),
                  C=c('D'), D=c(4, 4, 5, 5, 6, 6))

I have two lists like 'one' and 'two'. This lists contain several thousand data frames. I want to combine all of these into one data frame. I tried rbind, but I ran into issues because the dimensions of the data frames in the list vary. The end result should be what I have called goal_df

We can use

library(rowr)
do.call(cbind.fill, c(list(do.call(rbind, one), do.call(rbind, two)), fill = NA))

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