[R] NA and logical indexes

From: Sebastian P. Luque <spluque_at_gmail.com>
Date: Fri, 28 Nov 2008 15:25:36 -0600


Hi,

I vaguely remember this issue being discussed at some length in the past, but am having trouble relocating the proper thread (defining an adequate search string to do so):

---<---------------cut here---------------start-------------->---

R> foo <- data.frame(A=gl(2, 5, labels=letters[1:2]), X=runif(10))
R> foo$A[1] <- NA
R> foo$A == "b"

 [1] NA FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE R> foo$A[foo$A == "b"]
[1] <NA> b b b b b

Levels: a b
R> foo$X[foo$A == "b"]
[1] NA 0.4425 0.7164 0.3171 0.1967 0.8300
R> foo[foo$A == "b", ]
      A      X
NA <NA>     NA
6     b 0.4425
7     b 0.7164
8     b 0.3171
9     b 0.1967

10 b 0.8300
---<---------------cut here---------------end---------------->---

Why is foo$X[1] set to NA in that last call?

Cheers,

-- 
Seb

______________________________________________
R-help_at_r-project.org mailing list
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.
Received on Fri 28 Nov 2008 - 21:28:51 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 Fri 28 Nov 2008 - 22:30:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive