I want to use a separate dataframe to perform a mutate on test as follows:
library(tidyverse)
test <- tribble(
~col1, ~col2, ~col3,
"one", "a", "b",
"two", "b", "c",
"three", "c", "d"
)
mutator <- tribble(
~mutate_from, ~mutate_to,
"a", "X",
"b", "X"
)
Desired output:
> test
# A tibble: 3 x 3
col1 col2 col3
<chr> <chr> <chr>
1 one a X
2 two b X
3 three c d
I am stuck as to how I can implement this:
test %>%
mutate(col3 = map(mutator, ~.x %>% ?))
The end goal is to probably have 30 or so observations in mutator, so I am looking to functionise this somehow.