Skip to contents

Scales values using quantiles instead of min/max for robustness to outliers.

Usage

normalize_robust(x, lower_quantile = 0.05, upper_quantile = 0.95, na.rm = TRUE)

Arguments

x

Numeric vector

lower_quantile

Lower quantile for scaling (default: 0.05)

upper_quantile

Upper quantile for scaling (default: 0.95)

na.rm

Logical; remove NA values when computing quantiles?

Value

Numeric vector scaled approximately to the range 0 to 1, with outliers potentially outside this range

Examples

# With outliers
x <- c(1, 2, 3, 4, 5, 100)  # 100 is an outlier
normalize_robust(x)
#> [1] -0.003333333  0.010000000  0.023333333  0.036666667  0.050000000
#> [6]  1.316666667