Hi, all. The help file for tapply says that if simplify is true, and the result of the calculation is always a scalar, then tapply will return a vector. Nonetheless:> t1 <- tapply(runif(10), rep(1:5, 2), mean) > is.vector(t1)[1] FALSE> is.array(t1)[1] TRUE>I have found this in version 0.65.1 on an SGI running Irix 6.5, and on a Mac running Linux-PPC. I've also seen it on an Intel machine running RedHat 6.0. I noticed this because some results that I expected to be vectors couldn't be combined into a data frame (Error: can't coerce array into a data.frame). It seems that the check and conversion simply never happens. One way to fix this is to simply add these few lines to the end of the function (just before the value "ansmat" is returned: if(length(dim(ansmat)) == 1){ dim(ansmat) <- NULL names(ansmat) <- namelist[[1]] } I wouldn't be surprised to find that there's a more elegant way to do this. Perhaps ansmat[index] should be returned instead of ansmat? But I haven't tested this extensively, so I don't know whether it might break something else. Hope this report helps. Thanks for the terrific software. Matt Wiener -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
maechler@stat.math.ethz.ch
1999-Nov-11 10:54 UTC
tapply not simplifying to vector? (PR#320)
>>>>> "MatW" == Matthew Wiener <mcw@ln.nimh.nih.gov> writes:MatW> The help file for tapply says that if simplify is true, and the MatW> result of the calculation is always a scalar, then tapply will MatW> return a vector. MatW> Nonetheless: >> t1 <- tapply(runif(10), rep(1:5, 2), mean) >> is.vector(t1) R> [1] FALSE >> is.array(t1) R> [1] TRUE <....> all correct. The question really is if the bug is in the code or the documentation. Here you get a 1D array, something quite rare (but appearing more and more in recent discussions...). One could argue that the current behavior of tapply() to always return an array if simplify = TRUE is more consistent, than what the doc says should happen (coercing 1D arrays to vectors). Otoh, the protoype *does* return a vector in this case, and 1D arrays can be a pain... in other places. I'm pro fixing this. and I'll do if I don't hear protests.. MatW> <....> MatW> Hope this report helps. yes indeed, thank you! R's quality is growing partly because of such fine bug reports! MatW> Thanks for the terrific software. you're welcome! Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
maechler@stat.math.ethz.ch
1999-Nov-11 15:49 UTC
tapply not simplifying to vector? (PR#320)
>>>>> "PD" == Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:PD> maechler@stat.math.ethz.ch writes: >> I'm pro fixing this. >> and I'll do if I don't hear protests.. PD> Protest!... >> tapply(Ozone,list(Month=Month),mean,na.rm=T) PD> Month PD> May June July August September PD> 23.61538 29.44444 59.11538 59.96154 31.44828 PD> Notice the "Month" in the output. >> dput(tapply(Ozone,list(Month=Month),mean,na.rm=T)) PD> structure(c(23.6153846153846, 29.4444444444444, 59.1153846153846, PD> 59.9615384615385, 31.4482758620690), .Dim = 5, .Dimnames = structure(list( PD> Month = c("May", "June", "July", "August", "September")), .Names = "Month")) PD> Notice that the Month is the tag name of the single component of the PD> dimnames vector, it will disappear if you try coercing it to a vector. Completely agree with your argument. --> I'll change the documentation Kurt: Another (R<->S) difference for the FAQ. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._