[Rd] mean(trim=, c(NA,...), na.rm=FALSE) does not return NA

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Mar 18 11:57:04 CET 2010


On Tue, 16 Mar 2010, William Dunlap wrote:

> Both of the following should return NA,
> but do not in "R version 2.11.0 Under
> development (unstable) (2010-03-07 r51225)"
> on 32-bit Windows:

Nor in any version of R in the last several years (e.g. 2.1.0)

>  > mean(c(1,10,100,NA), trim=.1)
>  Error in sort.int(x, partial = unique(c(lo, hi))) :
>    index 4 outside bounds
>  > mean(c(1,10,100,NA), trim=.26)
>  [1] 55
>
> With na.rm=TRUE they give the correct results.

But the fix is easy and I've done so in R-devel, thank you.

> (mean() would be so much simpler if we didn't
> have to worry about the seldom-used trim=
> argument.)

Only a little.  I think the drawback is more conceptual: a trimmed 
mean needs order-able data whereas 'mean' in its usual sense does not.

> Bill Dunlap
> Spotfire, TIBCO Software


-- 
Brian D. Ripley,                  ripley at 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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list