From ggrothendieck at gmail.com  Mon Feb  9 16:59:39 2015
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Mon, 9 Feb 2015 10:59:39 -0500
Subject: [Rd] xtabs and NA
In-Reply-To: <54D8BBA1.5030409@ivt.baug.ethz.ch>
References: <54D8BBA1.5030409@ivt.baug.ethz.ch>
Message-ID: <CAP01uRn-fCa222jXu7Z+VzqhVUohjpGwFcbpXeOn5xH7BaBRLw@mail.gmail.com>

On Mon, Feb 9, 2015 at 8:52 AM, Kirill M?ller
<kirill.mueller at ivt.baug.ethz.ch> wrote:
> Hi
>
>
> I haven't found a way to produce a tabulation from factor data with NA
> values using xtabs. Please find a minimal example below, it's also on R-pubs
> [1]. Tested with R 3.1.2 and R-devel r67720.
>
> It doesn't seem to be documented explicitly that it's not supported. From
> reading the code [2] it looks like the relevant call to table() doesn't set
> the "useNA" parameter, which I think is necessary to make NAs show up in the
> result.
>
> Am I missing anything? If this a bug -- would a patch be welcome? Do we need
> compatibility with the current behavior?
>
> I'm aware of workarounds, I just prefer xtabs() over table() for its
> interface.
>

Passing table the output of model.frame would still allow the use of a
formula interface:

> mf <- model.frame( ~ data, na.action = na.pass)
> do.call("table", c(mf, useNA = "ifany"))

   a    b    c <NA>
   1    1    1    1


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



[Rd] xtabs and NA
Gabor Grothendieck