vector1 = c(1,2,3,NA)
condition1 = (vector1 == 2)
vector1[condition1]
vector1[condition1==TRUE]
In the above code, the condition1 is "FALSE TRUE FALSE NA", and the 3rd and the 4th lines both gives me the result "2 NA" which is not I expected.
I wanted elements whose values are really '2', not including NA.
Could anybody explain why R is designed to work in this way? and how I can get the result I want with a simple command?
?NA
for details – Gerda