Dear all,
(This issue was previously reported on Bugzilla
(https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17770) and discussed on
Stack Overflow (https://stackoverflow.com/q/61240049).)
The documentation of xtabs says:
"na.action: When it is na.pass and formula has a left hand side (with counts),
sum(*, na.rm = TRUE) is used instead of sum(*) for the counts."
However, this is not the case:
DF <- data.frame(group = c("a", "a", "b", "b"),
count = c(NA, TRUE, FALSE, TRUE))
xtabs(formula = count ~ group,
data = DF,
na.action = na.pass)
# group
# a b
# 1
In the code, na.rm is TRUE if and only if na.action = na.omit:
na.rm <-
identical(naAct, quote(na.omit)) || identical(naAct, na.omit) ||
identical(naAct, "na.omit")
xtabs(formula = count ~ group,
data = DF,
na.action = na.omit)
# group
# a b
# 1 1
The example works as documented if we change the code to:
na.rm <-
identical(naAct, quote(na.pass)) || identical(naAct, na.pass) ||
identical(naAct, "na.pass")
However, there may be something I am missing, and na.omit may be necessary for
something else...
Best regards,
Thomas
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel