[Rd] small inconistency: sapply & median (PR#702)

ripley@stats.ox.ac.uk ripley@stats.ox.ac.uk
Mon, 23 Oct 2000 22:12:02 +0200 (MET DST)


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