Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The initial report was addressed by Martin Maechler. The following is related to comment 3.
I went through the code for xtabs to understand the behavior noted by Thomas Soeiro and I believe there is no bug in the code but the documentation could include some clarification to cover this.
When the example is executed:
what enters to the
model.frame()
function insidextabs()
isstats::model.frame(formula = cbind(B, C) ~ A, data = x, na.action = na.omit)
with data being
na.omit
will remove all the lines containing anNA
, i.e. all combinations of A-B and A-C in a row, resulting in the output shown in comment 3:To avoid this, a user should not use
cbind(B, C)
. Instead something like this:By doing this, the table that goes into
model.frame()
and gets na.omited isand then
And only the combination of A-B or A-C that has NA is filtered.
In summary,
na.action
is called overdata
(the original data frame) instead of the result ofmodel.frame()
. This argument also has an impact on how NAs are treated insidesum()
, ifna.action = na.pass
, thenna.rm = FALSE
insidesum()
, otherways will beTRUE
.I propose a patch to include a sentence in the details section to make this behavior more clear.
Argument section
Description