There is some logic to getting something that you don't know what is when you 
don't know whether you want it or not. It is certainly more informative than 
not getting anything, just like if you indexed with FALSE.

However, a more straightforward argument is that when you use integer indexing 
as a lookup table, as in

color <- c("red","blue")[gender]

then clearly you want NA if gender is NA. The rest then follows from coercion 
rules: NA is by default mode "logical" and much confusion could happen if 
x[NA]!=x[NA_integer], for instance x[c(1,NA)] != c(x[1], x[NA]).

-pd

> On 16 Jan 2019, at 08:29 , PIKAL Petr <petr.pi...@precheza.cz> wrote:
> 
> I believe that this behaviour has some reason, because you compare 2 to NA 
> and NA is basically "I do not know". So it could be 2 and therefore also rows 
> with NA are returned. If I am wrong, I hope R gurus will correct me.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd....@cbs.dk  Priv: pda...@gmail.com

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to