Re: [R] NA and logical indexes

From: Sebastian P. Luque <>
Date: Fri, 28 Nov 2008 16:35:13 -0600

On Fri, 28 Nov 2008 22:01:15 -0000 (GMT), (Ted Harding) <> wrote:


> It is not!

Oops, of course, I meant to say "return" rather than "set" :-/


> NA can seem to have a bewildering logic, but it all becomes clear if
> you interpret NA as "value unkown".

> You asked for foo[foo$A == "b", ]. What happens is that when the test
> foo$A == "b" encounters f$A[1] it sees NA, so it does not know what
> the value is. Hence it does not know whether this row of foo satisfies
> the test. Hence the entire row is of unkown status. Hence a row is
> output all of whose elements (including the row label, i.e. the row
> number) are flagged "unknown", i.e. NA.

> AFter all, if it gave the value of foo$X[1] = 0.5013591, and you
> subsequently acessed foo[foo$A == "b",][1,2] and got 0.5013591, you
> would presumably proceed as though this was a value corresponding to a
> case where foo$A == "b". But it is not -- since foo$A[1] = NA, you
> don't know whether that is the case. Hence you don't know the value of
> foo[foo$A == "b",][1,2].

> Clear? ( :)) Hoping this helps, Ted.

Crystal! It's something that one needs to be extra careful with when playing with logicals.

Thanks Ted,


______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 28 Nov 2008 - 22:38:32 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 29 Nov 2008 - 09:30:28 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive