I have 3 lists (dataset1, dataset2, dataset3) and each of the list contains multiple dataframes which are different. However, in each of the list, the order of the dataframes is the same (i.e. the first dataframe in list 1, list 2 and list 3 have the same headers, and similarly for the second, third fourth dataframes etc.)
I was thinking of creating a loop to combine the 3 lists of dataframes into 1 list of dataframes. Since each of the dataframes are in the same order in all lists, I tried using the following code:
library(purr)
combined_data <- pmap(dataset1,
dataset2,
dataset3,
~rbind(..1,..2,..3))
Instead, R returned an error "Error: Element 1 has length 51, not 1 or 90."
I did a check and the first dataframe in all 3 datasets are all "List of 51", while the third dataframe in all 3 datasets are all "List of 90".
However, when i ran the following code:
combined_data <- map2(dataset1,
dataset2,
~rbind(.x,.y))
combined_data <- map2(combined_data,
dataset3,
~rbind(.x,.y))
It works exactly the way I wanted it to. Hence, I would like to learn from my mistake whether there is anything wrong with my code when I used pmap, especially since I will need to frequently do it on multiple list in the future, and using map2 won't be that sustainable. Thank you all!
transpose(list(dataset1, dataset2, dataset3)) %>% map(bind_rows))? Or if you just want everything together in onemap(map(list(dataset1, dataset2, dataset3), bind_rows), bind_rows). Example data is really required for us to tell you why with confidence.