jutans@utans.u-net.com
2000-Oct-23 19:13 UTC
[Rd] small inconistency: sapply & median (PR#702)
Full_Name: Joachim Utans Version: 1.1.1 OS: NT4 (SP6) Submission from: (NULL) (195.102.198.233) There seems to be a small inconsistency with using median in sapply with handling names (looks like it has to do with the different handling when the length is even/odd) Specifically, sapply will concatenate listelement names and a member name if the length of the member is odd. Example follows:> TMP.list_list(item1=c(a1=1,a2=2,a3=3), item2=c(b1=1,b2=2)) > TMP.list$item1 a1 a2 a3 1 2 3 $item2 b1 b2 1 2> sapply(TMP.list, mean)item1 item2 2.0 1.5> sapply(TMP.list, median)item1.a2 item2 !!!!!!!!!!!! note the ".a2" 2.0 1.5>> sapply(TMP.list, median, USE.NAMES=F)item1.a2 item2 2.0 1.5> lapply(TMP.list, median)$item1 a2 2 $item2 [1] 1.5 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
ripley@stats.ox.ac.uk
2000-Oct-23 20:12 UTC
[Rd] small inconistency: sapply & median (PR#702)
On Mon, 23 Oct 2000 jutans@utans.u-net.com wrote:> Full_Name: Joachim Utans > Version: 1.1.1 > OS: NT4 (SP6) > Submission from: (NULL) (195.102.198.233) > > > There seems to be a small inconsistency with using median in sapply with > handling names (looks like it has to do with the different handling when the > length is even/odd) > Specifically, sapply will concatenate listelement names and a member name if the > length of the member is odd.The apparent inconsistency is in> median(c(a1=1,a2=2,a3=3))a2 2> median(c(b1=1,b2=2))[1] 1.5 which makes sense as in the first case the median is an element of the input, and in the second it is not. Given that, sapply is doing perfectly sensible things. The prototype has an x <- as.vector(x) in its median, and so strips the names from x. If you really want that, try sapply(TMP.list, function(x) as.vector(median(x))) item1 item2 2.0 1.5 I suspect this is a feature, not a bug. -- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._