Remove data outliers based on the interquartile range.
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] -0.80750138 -8.34333037 -6.00760886 -1.57208442 -0.07399441 -4.66393497
#> [7] -4.97777389 -2.89767245 -7.32881987 -7.72521511 0.87460066 0.17494063
#> [13] 0.03424133 0.32038573 0.40232824 0.19566983 0.40353812 0.06366146
#> [19] 0.38870131 0.97554784