# # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- winsorize <- function(x,p=0.2){ n = length(x) if( n==0 ) return(x) g = floor(p*n) xs = sort(x) xs[1:g] = xs[g+1] # the first "g" elements get the smallest value not trimmed xs[(n-g+1):n] = xs[n-g] # the last "g" elements get the largest value not trimmed return(xs) }