[R] Inexplicably different results using subset vs bracket notation on logical variable
Peter Ehlers
ehlers at ucalgary.ca
Tue Aug 28 20:08:48 CEST 2012
On 2012-08-28 07:44, Mauricio Cornejo wrote:
> William, David, and Peter,
>
>
> Thank you all so much for your help on this. Though I had read the help files on 'subset' and '[', I had not been able to discern from that text what the problem was. I could not have solved it without your help.
>
>
> The help file on 'subset' mentions "For ordinary vectors, the result is simply x[subset & !is.na(subset)]." However, since I was dealing with a data frame at the time, I failed to appreciate the relevance (but I get it now).
>
>
> I've gone back to read the help on '[' and I still don't see where this functionality is described. The page has section titled "NAs in indexing", whose content I interpret as being limited to NAs in the indices (and not in the returned values). I can't find any text in the documentation describing the subtle behavior you kindly pointed out.
Hmmm, it seems to me that the page is clear:
"... NA index picks an unknown element and so *returns* NA
in the corresponding element of ..."
(my emphasis)
Isn't that exactly what occurs?
Peter Ehlers
>
> Thanks again,
> Mauricio
> [[alternative HTML version deleted]]
>
More information about the R-help
mailing list