Full_Name: Martin Lenze Version: 1.3.0 22.06.2001 OS: win32,x86 Submission from: (NULL) (194.221.251.1) As a newbie I'm not sure, whether this is a bug, but I don't know how to get around this behaviour:> x <- list("A"=rep(c(1:5),30),+ "B"=c(rep(letters[1:3],30),rep(letters[2:4],20)))> y <- as.data.frame(x) > xtabs(~A+B,y)B A a b c d 1 6 10 10 4 2 6 10 10 4 3 6 10 10 4 4 6 10 10 4 5 6 10 10 4> 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". Kindest regards M. Lenze -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Sun, 5 Aug 2001 martin.lenze@to.com wrote:> Full_Name: Martin Lenze > Version: 1.3.0 22.06.2001 > OS: win32,x86 > Submission from: (NULL) (194.221.251.1) > > > As a newbie I'm not sure, whether this is a bug, but I don't know how to get > around this behaviour: > > x <- list("A"=rep(c(1:5),30), > + "B"=c(rep(letters[1:3],30),rep(letters[2:4],20))) > > y <- as.data.frame(x) > > xtabs(~A+B,y) > B > A a b c d > 1 6 10 10 4 > 2 6 10 10 4 > 3 6 10 10 4 > 4 6 10 10 4 > 5 6 10 10 4 > > 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".The line x <- if (is.null(y)) do.call("table", mf) should be x <- if (is.null(y)) do.call("table", by) Currently drop.unused.levels=TRUE is ignored unless there is a response. -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._