Skip to content

Instantly share code, notes, and snippets.

@thanhleviet
Created May 17, 2018 12:05
Show Gist options
  • Save thanhleviet/0626c88375e93a396221442cbf21e8a7 to your computer and use it in GitHub Desktop.
Save thanhleviet/0626c88375e93a396221442cbf21e8a7 to your computer and use it in GitHub Desktop.
Subset with multiple conditions
mtcars %>%
mutate(
selected = case_when(
cyl == 6 & carb == 4 ~ "yes",
cyl == 8 & carb == 8 ~ "yes",
TRUE ~ "no"
)
) %>%
filter(selected == "yes") %>%
select(-selected)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment