Skip to contents

Remove data outliers based on the interquartile range.

Usage

removeOutliers(x, k = 1.5)

Arguments

x

vector of data.

k

factor to applied to the interquartile range (default = 1.5).

Value

A numeric vector with the same length as input vector.

Details

The interquartile range IQR is computed from input dataset as IQR = Q3 - Q1, where Q1 is 25th percentile and Q3 is the 75th percentile. Values larger than Q3 + k * IQR and smaller than Q1 - k * IQR are deemed as outliers and substituted with NA's.

The default value of k is 1.5.

Examples

mydata <- c(-10 * runif(10), runif(10))
removeOutliers(mydata)
#>  [1] -6.54810113 -6.52505679 -5.77710274 -6.91915833 -2.05544303 -0.41997104
#>  [7] -8.45002759 -1.33915163 -2.86775807 -3.66580217  0.68291383  0.31112961
#> [13]  0.67865915  0.25481233  0.60789262  0.88768903  0.09106843  0.78727299
#> [19]  0.26383883  0.01180341