Created
August 10, 2017 18:50
-
-
Save marcmtk/f4b18170080a45b64d4f0254a49a0a06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(rlang) | |
replace_value <- function(.data, var, from, to) { | |
var <- enquo(var) | |
mutate(.data, !!quo_name(var) := if_else(UQ(var) == from, to, !!var)) | |
} | |
mtcars %>% | |
replace_value(gear, 4, 8) %>% | |
replace_value(vs, 0, NA_real_) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment