From ripley at stats.ox.ac.uk  Thu Mar 18 11:57:04 2010
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Thu, 18 Mar 2010 10:57:04 +0000 (GMT)
Subject: [Rd] mean(trim=, c(NA,...), na.rm=FALSE) does not return NA
In-Reply-To: <77EB52C6DD32BA4D87471DCD70C8D70002A0FD42@NA-PA-VBE03.na.tibco.com>
References: <77EB52C6DD32BA4D87471DCD70C8D70002A0FD42@NA-PA-VBE03.na.tibco.com>
Message-ID: <alpine.LFD.2.00.1003181050330.26151@gannet.stats.ox.ac.uk>

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



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