I have the following data frame:
dat <- tibble(
nm = letters[c(1:5)] ,
g1 = c(1, 1, 2, NA, 2),
g2 = c(1, NA, 1, NA, 2),
ga = c(1 :3, NA, 5)
)
It looks like this:
> dat
# A tibble: 5 × 4
nm g1 g2 ga
<chr> <dbl> <dbl> <dbl>
1 a 1 1 1
2 b 1 NA 2
3 c 2 1 3
4 d NA NA NA
5 e 2 2 5
What I want to do is to exclude row when all the column that starts with "g" are NAs. Resulting in this:
nm g1 g2 ga
a 1 1 1
b 1 NA 2
c 2 1 3
e 2 2 5
I tried this but failed:
dat %>%
filter_at(vars(contains("g")), !all_vars(is.na(.)))
That gives:
Error in inherits_any():
! Quosures can only be unquoted within a quasiquotation context.
# Bad: list(!!myquosure)
# Good: dplyr::mutate(data, !!myquosure)