Created
May 11, 2016 08:15
-
-
Save Nicktz/e01075fa4f0c51d74431d31751879321 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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