Last active
June 26, 2019 15:20
-
-
Save jennybc/a5c0710ec9d024cbd5c289a3d7569267 to your computer and use it in GitHub Desktop.
Faking tidyr::drop_na(..., logic = "all")
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(tidyverse) | |
(df <- tibble( | |
x = c(1, NA, 3, NA), | |
y = c(1, NA, NA, 4), | |
z = 1:4 | |
)) | |
#> # A tibble: 4 × 3 | |
#> x y z | |
#> <dbl> <dbl> <int> | |
#> 1 1 1 1 | |
#> 2 NA NA 2 | |
#> 3 3 NA 3 | |
#> 4 NA 4 4 | |
df %>% drop_na(x:y) | |
#> # A tibble: 1 × 3 | |
#> x y z | |
#> <dbl> <dbl> <int> | |
#> 1 1 1 1 | |
allNA <- . %>% map(is.na) %>% flatten_lgl() %>% all() | |
df %>% | |
filter(!pmap_lgl(select(., x:y), lift_ld(allNA))) | |
#> # A tibble: 3 × 3 | |
#> x y z | |
#> <dbl> <dbl> <int> | |
#> 1 1 1 1 | |
#> 2 3 NA 3 | |
#> 3 NA 4 4 |
Well, if you were provoked...
This is good because you can select the columns you want to be sensitive to the operation. The other options are less specific or specific to all columns being NA.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Provoked by https://twitter.com/noamross/status/857609829480792064