[Rd] table(exclude = NULL) always includes NA
Martin Maechler
maechler at stat.math.ethz.ch
Sat Sep 10 19:49:03 CEST 2016
>>>>> Suharto Anggono Suharto Anggono <suharto_anggono at yahoo.com>
>>>>> on Sat, 10 Sep 2016 02:36:54 +0000 writes:
> Looking at the code of function 'table' in R devel r71227, I see that the part "remove NA level if it was added only for excluded in factor(a, exclude=.)" is not quite right.
> In
> is.na(a) <- match(a0, c(exclude,NA), nomatch=0L) ,
> I think that what is intended is
> a[a0 %in% c(exclude,NA)] <- NA .
yes.
> So, it should be
> is.na(a) <- match(a0, c(exclude,NA), nomatch=0L) > 0L
> or
> is.na(a) <- as.logical(match(a0, c(exclude,NA), nomatch=0L)) .
> The parallel code
> is.na(a) <- match(a0, exclude, nomatch=0L)
> is to be treated similarly.
indeed. I may have been very wrongly thinking that `is.na<-`
coerced its value to logical... or otherwise not thinking at all ;-)
> Example that gives wrong result in R devel r71225:
> table(3:1, exclude = 1)
> table(3:1, exclude = 1, useNA = "always")
> --------------------------------------------
Thanks a lot, Suharto. You are entirely correct.
I'm amazed that table(*, exclude = *) seems so rarely used / tested,
that this has gone undetected for almost four weeks.
It is fixed now with svn r71230.
Martin
More information about the R-devel
mailing list