Say we create a vector like this:
v <- c(1, 2, 2, NA)
And we test it for a simple condition:
> v == 1
[1] TRUE FALSE FALSE NA
Subsetting the vector using this condition, we obtain this:
> v[v == 1]
[1] 1 NA
Why is the NA
included in the subset when it clearly doesn't meet the condition? I'm aware that NA == 1
returns NA
, but why is the subsetting not taking TRUE
values exclusively? What am I missing here?