This simple function uses boxplot.stats() to determine outliers and removes them from the vector.

remove_outliers(x, coef = 1.5)

Arguments

x

a vector of values

coef

a multiple of the IQR that is allowed at maximum to keep values within the accepted range

Examples

remove_outliers(c(1,2,1,2,1,2,8))
#> 1 outlier removed
#> [1] 1 2 1 2 1 2

remove_outliers(c(1,2,1,2,1,2))
#> 0 outliers removed
#> [1] 1 2 1 2 1 2