I am using purrr
and want to use map
or on a list list1
within a tibble my_tibble
in combination with an external dataframe my_dataframe
, the idea is for my_dataframe
to be merged to every item of list1
:
library(dplyr)
library(purrr)
df1 <- tibble(X = 1:3, A = c("a", "b", "c"))
df2 <- tibble(X = 1:3, A = c("d", "e", "f"))
df3 <- tibble(X = 1:3, A = c("x", "y", "z"))
my_tibble <- tibble (list1 = list(df1, df2, df3), list2 = list(df1, df2, df3))
my_dataframe <- tibble(D = 1:9, A = c("d", "e", "f","a", "b", "c","x", "y", "z"))
my_tibble <- my_tibble %>% mutate (list1 = map (list1, function (.x) {
.x %>% left_join(my_dataframe) } ))
- The example actually works so no answer is needed