s-news
[Top] [All Lists]

NA in logical tests

To: s-news@lists.biostat.wustl.edu
Subject: NA in logical tests
From: Eva Goldwater <goldwater@schoolph.umass.edu>
Date: Thu, 18 Nov 2004 17:41:53 -0500 (EST)
I am puzzled by the fact that NA apparently test true for any logical
condition.  For example:

> y <- c(-1,0,1,NA)
> y[y>0]
[1]  1 NA
> y[y<=0]
[1] -1  0 NA

I would have expected that NA should fail all logical tests.  Can anyone
explain this weird behaviour? Is there an option that controls it, or do I
always have to eliminate NAs manually?

I am using S-Plus 6.2 on Windows.  Thank you,

Eva Goldwater                           email: goldwater@schoolph.umass.edu
Biostatistics Consulting                Phone: (413) 545-2949
418 Arnold House                        Fax:   (413) 545-1645
715 North Pleasant Street
University of Massachusetts
Amherst, MA 01003-9304

<Prev in Thread] Current Thread [Next in Thread>