[Rd] xyTable(x,y) versus table(x,y) with NAs

Viechtbauer, Wolfgang (NP) wo||g@ng@v|echtb@uer @end|ng |rom m@@@tr|chtun|ver@|ty@n|
Tue Apr 25 10:24:52 CEST 2023


Hi all,

Posted this many years ago (https://stat.ethz.ch/pipermail/r-devel/2017-December/075224.html), but either this slipped under the radar or my feeble mind is unable to understand what xyTable() is doing here and nobody bothered to correct me. I now stumbled again across this issue.

x <- c(1, 1, 2, 2,  2, 3)
y <- c(1, 2, 1, 3, NA, 3)
table(x, y, useNA="always")
xyTable(x, y)

Why does xyTable() report that there are NA instances of (2,3)? I could understand the logic that the NA could be anything, including a 3, so the $number value for (2,3) is therefore unknown, but then the same should apply so (2,1), but here $number is 1, so the logic is then inconsistent.

I stared at the xyTable code for a while and I suspect this is coming from order() using na.last=TRUE by default, but in any case, to me the behavior above is surprising.

Best,
Wolfgang



More information about the R-devel mailing list