I want to drop only the rows where the values in columns "c2", "c3" ,"c4" are missing.
Tried using 'complete.cases' but it removes the rows based on "OR" logic. What i want to do is the AND logic. That is, remove the row only if C2 AND C3 AND C4 are missing.
Any help on this would be highly appreciated.
library(tibble)
library(dplyr)
dat <- tibble(
a = c(1, NA, 3, NA, 5, 6, NA),
b = c(8, 9, 10, 11, 12, 13, 14),
c = c(15, NA, 17, NA, NA, 20, 21),
d = c(22, NA, 23, 24, 25, 26, 26)
)
# drop rows only if values in cols a, c, and d are NA
dat |>
filter(!if_all(.cols = c(a,c,d), .fns = is.na))
I'm not in the {base} is always best Church of the One True Faith, but I found once I got over the punctuation-intensive aspect, syntax is easier with fewer and more explicit parameters to stuff into my addled head.
indeed, your approach with base R is much more clear about how the conditions are tested, and it's a good reminder of how base functions and operators can accomplish so much
Your solution works like a charm! Thanks a lot for that.
And next time when I am posting, will keep in mind about the good practices such as producing a reproducible example without just putting the screenshot.