From nalimilan at club.fr  Thu Jan 19 13:58:31 2017
From: nalimilan at club.fr (Milan Bouchet-Valat)
Date: Thu, 19 Jan 2017 13:58:31 +0100
Subject: [Rd] xtabs(), factors and NAs
Message-ID: <1484830711.8924.41.camel@club.fr>

Hi all,

I know this issue has been discussed a few times in the past already,
but Martin Maechler suggested in a bug report [1] that I raise it here.

Basically, there is no (easy) way of printing NAs for all variables
when calling xtabs() on factors. Passing 'exclude=NULL,
na.action=na.pass' works for character vectors, but not for factors.

> test <- data.frame(x=c("a",NA))
> xtabs(~ x, exclude=NULL,
na.action=na.pass, data=test)
x
a?
1?

> test <- data.frame(x=factor(c("a",NA)))
> xtabs(~ x, exclude=NULL,
na.action=na.pass, data=test)
x
a?
1?


Even if it's documented, this inconsistency is annoying. When checking
data, it is often useful to print all NA values temporarily, without
calling addNA() individually on all crossed variables.

Would it make sense to add a new argument similar to table()'s useNA
which would behave the same for all input vector types?


Regards


1: https://bugs.r-project.org/bugzilla/show_bug.cgi?id=14630



[Rd] xtabs(), factors and NAs
Milan Bouchet-Valat