vector1 = c(1,2,3,NA)
condition1 = (vector1 == 2)
vector1[condition1]
vector1[condition1==TRUE]
In the above code, condition 1 is “FALSE TRUE FALSE NA”, and the 3rd and 4th lines give me the result “2 NA”, which I did not expect.
I need elements whose values are really "2", not including NA.
Can someone explain why R is designed to work this way? and how can I get the result that I want with a simple command?
source
share