[R] NA rows appeared in data.frame

peter dalgaard pd@|gd @end|ng |rom gm@||@com
Wed Jan 16 20:04:38 CET 2019


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.pikal using 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.mes using cbs.dk  Priv: PDalgd using gmail.com



More information about the R-help mailing list