I have the following data frame:
a b c
x 1 1
x 1 NA
y NA 1
y 1 1
I would like to remove the rows containing at least an NA in any column(s), but only if the "a" column contains a "y". So, the result would be:
a b c
x 1 1
x 1 NA
y 1 1
So far I have tried this:
my_DF %>%
filter(!(any(is.na(.)) & a == "y"))
but the resulting data frame is the following:
a b c
x 1 1
x 1 NA
so this just removes any row in which "a" contains a "y", regardless of whether the row also contains NAs in at least one column.
How could I change the "any(is.na(.))" part of the command (I guess that is the wrong part) in other for it to work?