Skip to contents

Scales values to the range 0 to 1 using min-max normalization.

Usage

normalize_minmax(x, min_val = NULL, max_val = NULL, na.rm = TRUE)

Arguments

x

Numeric vector

min_val

Minimum value for scaling (default: min of x)

max_val

Maximum value for scaling (default: max of x)

na.rm

Logical; remove NA values when computing range?

Value

Numeric vector scaled to the range 0 to 1

Examples

normalize_minmax(c(10, 20, 30, 40, 50))
#> [1] 0.00 0.25 0.50 0.75 1.00
normalize_minmax(c(-5, 0, 5), min_val = -10, max_val = 10)
#> [1] 0.25 0.50 0.75