Skip to content

Instantly share code, notes, and snippets.

@gadenbuie
Last active August 3, 2018 12:49
Show Gist options
  • Save gadenbuie/40e531663cd92865a04bdecb6364ae93 to your computer and use it in GitHub Desktop.
Save gadenbuie/40e531663cd92865a04bdecb6364ae93 to your computer and use it in GitHub Desktop.
mutate(
df,
var = recode_if(var, in_group_1, "old1" = "new1"),
var = recode_if(var, in_group_2, "0" = "A", "1" = "B", "2" = "C", "3" = "D"),
var = recode_if(var, in_group_3, "a" = "A", "b" = "B", "c" = "C")
)
mutate(
df,
var = case_when(
in_group_1 && var == "old1" ~ "new1",
in_group_2 && var == "0" ~ "A",
in_group_2 && var == "1" ~ "B",
in_group_2 && var == "2" ~ "C",
in_group_2 && var == "3" ~ "D",
in_group_3 && var == "a" ~ "A",
in_group_3 && var == "b" ~ "B",
in_group_3 && var == "c" ~ "C",
TRUE ~ var
)
)
# https://git.io/fNiwU
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment