>>>>> "VO" == Vadim Organovich <[EMAIL PROTECTED]>
>>>>>     on Wed, 20 Aug 2008 12:30:38 -0500 writes:

    VO> Dear R-devel,
    VO> The median() function assigns a name, "NA", to its return value if the 
return value is NA and the input vector has names, otherwise the names 
attribute is NULL. This looks strange and inconsistent with the behavior of 
mean().

    VO> This inconsistency becomes a problem when median() is used inside user 
code that relies on consistent naming convention.

    VO> Thanks,
    VO> Vadim

    >> foo <- c(x=as.numeric(NA), y=as.numeric(NA), z=as.numeric(NA))
    >> names(mean(foo))
    VO> NULL
    >> names(median(foo))
    VO> [1] NA

    VO> ## no names in input
    >> foo <- rep(as.numeric(NA), 3)
    >> names(median(foo))
    VO> NULL

I agree that this is a slight blemish.
Note that it comes from this construct :

  > foo <- c(x=NA)
  > foo[FALSE]
  named numeric(0)
  > foo[FALSE][NA]
  <NA> 
    NA 

which seems "logical" if you ponder about it.

However, for the case of the median(), we do not return names
anyway, even in the case it might make sense,
e.g. I might expect

    median( c(a = 1, b=2, d=100))

to return  c(b = 2)
but it really simply returns (unnamed) 2.

So, I'm going to change median() to return unnamed also in these
border line cases.

Martin

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to