Suppose we have the following database:
ID x y
1 23 -3
2 2 51
3 -2 45
4 NA 2
5 NA -2
6 NA NA
I want to eliminate all the rows with negative values on the columns x and y, but I want to keep the NAs (that are written as the special value in R).
The result should be the following:
ID x y
2 2 51
4 NA 2
6 NA NA
I have tried using:
database <- database[!(database$x < 0 && database$x != "NA" || database$y < 0 && database$y != "NA")]
But it does not work, as it gives the error
'length(x) = 2 > 1' in coercion to 'logical(1)'
Which, from what I have seen, should be a problem of the new R version.
I have also tried using !is.na(), and substituting && and || to & and |, but it doesn't work.
Does anyone know how to solve this issue?