Skip to content
Prev 167282 / 398502 Next

Winsorizing Multiple Variables

Might work better to determine top and bottom for each column with  
quantile() using an appropriate quantile option,  and then process  
each variable "in place" with your ifelse logic.

I did find a somewhat different definition of winsorization with no  
sorting in this code copied from a Patrick Burns posting from earlier  
this year on R-SIG-Finance;

function(x, winsorize=5) {
            s <- mad(x) * winsorize
            top <- median(x) + s
            bot <- median(x) - s
            x[x > top] <- top
            x[x < bot] <- bot x }