Skip to content

Instantly share code, notes, and snippets.

@sfirke
Created March 7, 2018 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfirke/8754ed62b40bc57a56aa914625d60d32 to your computer and use it in GitHub Desktop.
Save sfirke/8754ed62b40bc57a56aa914625d60d32 to your computer and use it in GitHub Desktop.
Using split with magrittr's $%$ to reference the names of the listed data.frames
# I want to remove duplicate mpg rows where cylinder is 4
# Split, tinker with the data.frames by name, bind_rows
library(magrittr)
library(dplyr)
mtcars %>%
split(., .$cyl == 4) %$%
bind_rows(`FALSE`,
`TRUE` %>%
distinct(mpg, .keep_all = TRUE))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment