Reputation: 21232
I have two lists of dataframes. I would like to combine each dataframe in each of the list, one on top of the other using somehting like bind_rows or just rbind. The two lists have the columns with exact same names and order.
Something like combined <- map_df(rapheys_df_list, XGB_models_Prep, bind_rows)
which resulted in "Error: Index 1 must have length 1".
How can I join the two lists of dataframes into a combined single list where each dataframe in one list is combined by rows on top of the other?
Upvotes: 4
Views: 542
Reputation: 6459
Reduce(rbind, Map(rbind, rapheys_df_list, XGB_models_Prep))
# or, with the same result:
do.call(rbind, Map(rbind, rapheys_df_list, XGB_models_Prep))
Upvotes: 2
Reputation: 887163
We need map2
for binding two corresponding list
s
library(purrr)
map2_dfr(rapheys_df_list, XGB_models_Prep, bind_rows)
rapheys_df_list <- list(data.frame(col1 = 1:3, col2 = 4:6),
data.frame(col1 = 7:9, col2 = 10:12))
XGB_models_Prep <- list(data.frame(col1 = 2:5, col2 = 3:6),
data.frame(col1 = 4:6, col2 = 0:2))
Upvotes: 3