Skip to content
Prev 4861 / 15274 Next

how to winsorize data

On Wed, Sep 16, 2009 at 9:33 AM, Breno Neri <breno.neri at nyu.edu> wrote:
That will delete the extreme values from x, but if I understand the
process of winsorization correctly, the extreme values should be
*replaced* by the corresponding quantiles, no?

winsorize <- function(x, q=0.05) {
 extrema <- quantile(x, c(q, 1-q))	
 x[x<extrema[1]] <- extrema[1]
 x[x>extrema[2]] <- extrema[2]
 x
}
Min.  1st Qu.   Median     Mean  3rd Qu.     Max.
-1.55200 -0.54590 -0.03203 -0.01133  0.54230  1.46300
--
David M Smith <david at revolution-computing.com>
Director of Community, REvolution Computing www.revolution-computing.com
Tel: +1 (206) 577-4778 x3203 (San Francisco, USA)

Check out our upcoming events schedule at www.revolution-computing.com/events