Skip to content

Instantly share code, notes, and snippets.

@Nicktz
Created May 11, 2016 08:15
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 Nicktz/e01075fa4f0c51d74431d31751879321 to your computer and use it in GitHub Desktop.
Save Nicktz/e01075fa4f0c51d74431d31751879321 to your computer and use it in GitHub Desktop.
This is a useful means of using vector inputs in filters for dplyr:
Function_Name <- lazyeval::interp(~Function(a), a = as.name(VectorInput))
df %>%
filter_(Function_Name)
This applies the Function on the VectorInput to a filter.
E.g., to get complete cases for a vector, use:
LazyCompleteCases <- lazyeval::interp(~complete.cases(a), a = as.name(VectorInput))
LazyNonZero <- lazyeval::interp(~a != 0, a = as.name(VectorInput))
LazyQuantileTrim <- lazyeval::interp(~ a < quantile(a,probs = (1 - Filter), na.rm = TRUE), a = as.name(VectorInput))
Lazy
df %>%
filter_(LazyCompleteCases)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment