I'd like to pass either a named vector or two vectors to dplyr::recode. Let's say I've got:
library(dplyr)
set.seed(1)
x <- c("customer", sample(c("a", "b", "c"), 10, replace = TRUE))
recode_tbl <- tibble(letter = letters[1:3], fruit = c("apple", "banana", "cranberry"))
What I'd like to do is use the columns of recode_tbl to recode x, without having to specify the pairs manually as:
recode(x, a = "apple", b = "banana", c = "cranberry")
Something like:
recode(x, as.name(recode_tbl$letter) = recode_tbl$fruit)
That obviously doesn't work. I'm not averse to trying NSE but if someone could get the ball rolling that would be great.
Thanks.