I have been using the dplyr::recode() function to recode some variables. I have one character variable with some empty strings that I would also like to recode. But if I refer to the empty string in the arguments to the function, I get an error.
# input
x <- c("a", "b", "", "x", "y", "z")
# desired output
c("Apple", "Banana", "Missing", "x", "y", "z")
dplyr::recode(x, "a"="Apple", "b"="Banana", ""="Missing")
Error: attempt to use zero-length variable name
If I treat the empty string as a missing value, the function leaves it as an empty string.
dplyr::recode(x, "a"="Apple", "b"="Banana", .missing="Missing")
[1] "Apple" "Banana" "" "x" "y" "z"
How can I recode the values to get the desired output?