set.seed(1234)
x <- rnorm(100)
x[1] <- x[1] * 10
winsorize(x)
plot(x, type="l", main="Winsorization transformation")
lines(winsorize(x), col="red", lwd=2)
legend("bottomright", legend=c("Original distribution","With outliers removed"),
lty=c(1,1), col=c("black","red"))
# Behavior with NA value(s)
x[4] <- NA
winsorize(x) # returns x with original NA's
winsorize(x, na.rm=TRUE) # removes NA's
Run the code above in your browser using DataLab