Martin Maechler <maechler at stat.math.ethz.ch>
on Tue, 9 Aug 2016 15:35:41 +0200 writes:
Suharto Anggono Suharto Anggono via R-devel <r-devel at r-project.org>
on Sun, 7 Aug 2016 15:32:19 +0000 writes:
a <- c(1, 1, 2, 2, NA, 3); b <- c(2, 1, 1, 1, 1, 1)
table(a, b, exclude = NULL)
b
a 1 2
1 1 1
2 2 0
3 1 0
<NA> 1 0
a <- c(1, 1, 2, 2, NA, 3); b <- c(2, 1, 1, 1, 1, 1)
table(a, b, exclude = NULL)
b
a 1 2 <NA>
1 1 1 0
2 2 0 0
3 1 0 0
<NA> 1 0 0
table(a, b, useNA = "ifany")
b
a 1 2
1 1 1
2 2 0
3 1 0
<NA> 1 0
table(a, b, exclude = NULL, useNA = "ifany")
b
a 1 2 <NA>
1 1 1 0
2 2 0 0
3 1 0 0
<NA> 1 0 0
For the example, in R 3.3.1, the result of 'table' with
exclude = NULL includes NA even if NA is not present. It is
different from R 2.7.2, that comes from factor(exclude = NULL),
that includes NA only if NA is present.
I agree that this (R 3.3.1 behavior) seems undesirable and looks
wrong, and the old (<= 2.2.7) behavior for table(a,b,
exclude=NULL) seems desirable to me.
From R 3.3.1 help on 'table', in "Details" section:
'useNA' controls if the table includes counts of 'NA' values: the allowed values correspond to never, only if the count is positive and even for zero counts. This is overridden by specifying 'exclude = NULL'.
Specifying 'exclude = NULL' overrides 'useNA' to what value? The documentation doesn't say. Looking at the code of function 'table', the value is "always".
Yes, it should be documented what happens for this case,
(but read on ...)