# Create data with 3 outliers
x <- seq(0.1, 5, length=100)
x[98:100] <- c(100, 55, 250)
# Calculate Z score
Z <- outliers(x)
# Show number of extreme outliers using Z-score
length(Z[Z > 9.9])
# Remove extreme outliers
x <- x[-which(Z > 9.9)]
Run the code above in your browser using DataLab