From p.dalgaard@biostat.ku.dk  Sun Aug  5 19:43:52 2001
From: p.dalgaard@biostat.ku.dk (Peter Dalgaard BSA)
Date: 05 Aug 2001 20:43:52 +0200
Subject: [Rd] xtabs, drop.unused.levels (PR#1041)
In-Reply-To: martin.lenze@to.com's message of "Sun, 5 Aug 2001 20:03:32 +0200 (MET DST)"
References: <200108051803.UAA11343@pubhealth.ku.dk>
Message-ID: <x2puaal53r.fsf@blueberry.kubism.ku.dk>

martin.lenze@to.com writes:

> > y <- subset(y,B!="d")
> > xtabs(~A+B,y,drop.unused.levels=TRUE)
>    B
> A   a  b  c d
>   1 6 10 10 0
>   2 6 10 10 0
>   3 6 10 10 0
>   4 6 10 10 0
>   5 6 10 10 0
> 
> I'd expect "xtabs" to drop "d".

Yes, that's a bug. The culprit is

  do.call("table", mf)

using "mf" rather than "by" which was carefully computed to handle
drop.unused.levels a couple of lines above.

Actually, I think that table(by) would work just as well (and look better).

(A quick workaround could be y$B <- factor(y$B))
 
-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] xtabs, drop.unused.levels (PR#1041)
Peter Dalgaard BSA