Min-max normalization to scale values between 0 and 1.
normalize_minmax(x, inverse = FALSE)
Arguments
- x
Numeric vector.
- inverse
Logical. If TRUE, higher original values receive
lower normalized scores. Use for metrics where lower is better,
such as carbon footprint or energy intensity. Default FALSE.
Value
Numeric vector normalized to the 0 to 1 range. Returns 0.5
for all elements if the input has zero range.
Details
Formula: $$X_{norm} = \frac{X - X_{min}}{X_{max} - X_{min}}$$
Examples
normalize_minmax(c(10, 20, 30, 40, 50))
#> [1] 0.00 0.25 0.50 0.75 1.00
normalize_minmax(c(10, 20, 30, 40, 50), inverse = TRUE)
#> [1] 1.00 0.75 0.50 0.25 0.00