Skip to content

Instantly share code, notes, and snippets.

@marcmtk
Created August 10, 2017 18:49
Show Gist options
  • Save marcmtk/8000de9fc21f78f1b3ef89e18ccf9646 to your computer and use it in GitHub Desktop.
Save marcmtk/8000de9fc21f78f1b3ef89e18ccf9646 to your computer and use it in GitHub Desktop.
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