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

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
05 Aug 2001 20:43:52 +0200


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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._