I am just learning R, and trying to play around with indexing to help me understand. But, I try this code, and don't get what I expect:
> x
[1] 3 6 1 NA 2
> x[!is.na(x[x>2])]
[1] 3 6 NA 2
Shouldn't the results of the second command be those elements of x
that are not NA
and are GT 2
? In other words, it should return 3 6
. What am I not understanding about this?
x[!is.na(x) & x > 2]
– Rorschach