Re: [Rd] xtabs and NA

2015-02-13 Thread Kirill Müller

On 09.02.2015 16:59, Gabor Grothendieck wrote:

On Mon, Feb 9, 2015 at 8:52 AM, Kirill Müller
kirill.muel...@ivt.baug.ethz.ch wrote:
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))

abc NA
1111


Fair enough, this qualifies as a workaround, and IMO this is how xtabs 
should handle it internally to allow writing xtabs(~data, na.action = 
na.pass) -- or at least xtabs(~data, na.action = na.pass, exclude = 
NULL) if backward compatibility is desired. Would anyone with write 
access to R's SVN repo care enough about this situation to review a 
patch? Thanks.



-Kirill

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] xtabs and NA

2015-02-09 Thread Gabor Grothendieck
On Mon, Feb 9, 2015 at 8:52 AM, Kirill Müller
kirill.muel...@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))

   abc NA
   1111


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

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] xtabs and NA

2015-02-09 Thread Kirill Müller

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.


Thanks.


Best regards

Kirill


[1] http://rpubs.com/krlmlr/xtabs-NA
[2] 
https://github.com/wch/r-source/blob/780021752eb83a71e2198019acf069ba8741103b/src/library/stats/R/xtabs.R#L60



data - factor(letters[1:4], levels = letters[1:3])
data
## [1] abcNA
## Levels: a b c
xtabs(~data)
## data
## a b c
## 1 1 1
xtabs(~data, na.action = na.pass)
## data
## a b c
## 1 1 1
xtabs(~data, na.action = na.pass, exclude = numeric())
## data
## a b c
## 1 1 1
xtabs(~data, na.action = na.pass, exclude = NULL)
## data
## a b c
## 1 1 1
sessionInfo()
## R version 3.1.2 (2014-10-31)
## Platform: x86_64-pc-linux-gnu (64-bit)
##
## locale:
##  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
##  [3] LC_TIME=de_CH.UTF-8LC_COLLATE=en_US.UTF-8
##  [5] LC_MONETARY=de_CH.UTF-8LC_MESSAGES=en_US.UTF-8
##  [7] LC_PAPER=de_CH.UTF-8   LC_NAME=C
##  [9] LC_ADDRESS=C   LC_TELEPHONE=C
## [11] LC_MEASUREMENT=de_CH.UTF-8 LC_IDENTIFICATION=C
##
## attached base packages:
## [1] stats graphics  grDevices utils datasets  methods base
##
## other attached packages:
## [1] magrittr_1.5ProjectTemplate_0.6-1.0
##
## loaded via a namespace (and not attached):
## [1] digest_0.6.8evaluate_0.5.7  formatR_1.0.3 htmltools_0.2.6
## [5] knitr_1.9.2 rmarkdown_0.5.1 stringr_0.6.2 tools_3.1.2
## [9] ulimit_0.0-2

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel