[R] NA preserved in logical call - I don't understand this behavior because NA is not equal to 0
David Winsemius
dwinsemius at comcast.net
Sun Jul 18 21:45:10 CEST 2010
On Jul 18, 2010, at 2:52 PM, Hadley Wickham wrote:
>> The problem is in data.frame[ and any NA in a logical vector will
>> return a
>> row of NA's. This can be avoid by wrapping which() around the
>> logical vector
>> which seems entirely wasteful or using subset().
>
> The basic philosophy that causes this behaviour is sensible in my
> opinion: missing values must always be handled explicitly. Sure it's
> a bit of a hassle, but it being explicit prevents you from making
> major errors in an analysis.
How does this apply to the treatment of logical indexing in the
function "data.frame[" ? The returned value is not expected to have
the same number of rows as the source object and the profusion of
duplicate NA rows serves what purpose? Wouldn't it be more consistent
to have the constructs:
dfrm[which(logical_vector), ]
dfrm[logical_vector , ]
.... return the same object?
>
> In my opinion, the flaw is that R doesn't apply this philosophy
> entirely consistently: I think factor and table should default to
> exclude = NULL.
>
> Hadley
>
>
> --
> Assistant Professor / Dobelman Family Junior Chair
> Department of Statistics / Rice University
> http://had.co.nz/
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list