Remove outliers from a data frame column using a MAD-based robust filter
Source:R/B_remove_outlier.R
B_remove_outlier.RdThis function removes outliers from a specified column of a data frame
using a robust threshold based on the Median Absolute Deviation (MAD).
Values outside the interval median ± 3 * MAD are excluded.
The method is resistant to extreme values and does not assume normality.
Details
The MAD-based rule is a robust alternative to standard deviation filtering. It is particularly suitable for skewed or heavy-tailed distributions, where traditional z-score filtering may fail. If the column contains no variability (MAD = 0), the function will return the original data frame.
Examples
df <- data.frame(value = c(1, 2, 3, 100))
B_remove_outlier(df, "value")
#> [1] 1 2 3