From Wolfram MathWorld's explanation of Box-and-Whisker Plot outliers are defined as being the data points further than $3/2$ times the InterquartileRange
from the Mean
Median
.
removeoutlier[data_]:=Block[
{mean, iqr},
mean median = Mean[data]Median[data] ;
iqr = 3/2*InterquartileRange[data];
Select[data, ( meanmedian -iqr < # < mean+iqrmedian +iqr )& ]
]
Other functions also remove "outliers", for instance, the HampelFilter
, however, this uses a different definition of "outlier".
ResourceFunction["HampelFilter"][data2]