Created
November 13, 2018 19:43
-
-
Save romainfrancois/8ae15314143d3328414f7cb643b1c179 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
library(dplyr, warn.conflicts = FALSE) | |
library(purrr) | |
df <- tibble( | |
x1 = sample(c(-1, 0, 1), size = 1000, replace = TRUE), | |
x2 = sample(c(-1, 0, 1), size = 1000, replace = TRUE), | |
x3 = sample(c(-1, 0, 1), size = 1000, replace = TRUE), | |
x4 = sample(c(-1, 0, 1), size = 1000, replace = TRUE) | |
) | |
discard <- function(.data, ...) { | |
quos <- reduce(quos(...), function(x, y) expr(!!x & !!y)) | |
filter(.data, !(!!quos)) | |
} | |
discard(df, x1 == 0, x2 == 0, x3 == 0, x4 == 0) | |
#> # A tibble: 984 x 4 | |
#> x1 x2 x3 x4 | |
#> <dbl> <dbl> <dbl> <dbl> | |
#> 1 -1 1 1 1 | |
#> 2 0 0 -1 -1 | |
#> 3 1 0 1 1 | |
#> 4 -1 -1 1 1 | |
#> 5 -1 -1 0 1 | |
#> 6 1 0 -1 0 | |
#> 7 0 1 1 1 | |
#> 8 1 0 -1 -1 | |
#> 9 0 -1 1 0 | |
#> 10 -1 0 1 1 | |
#> # … with 974 more rows |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment