Skip to content

Instantly share code, notes, and snippets.

@marcmtk
Last active August 10, 2017 19:40
Show Gist options
  • Save marcmtk/1905818e24ee2b3aedf7c087bc214254 to your computer and use it in GitHub Desktop.
Save marcmtk/1905818e24ee2b3aedf7c087bc214254 to your computer and use it in GitHub Desktop.
```{r}
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_) %>%
head()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment