This function rescales variable(s) in a data.frame using min-max normalization with arbitrary min and max values.
Arguments
- df
data.frame
- vars
(character) variables to rescale
- min
(numeric) new minimum value (default 0)
- max
(numeric) new maximum value (default 1)
Details
Values are rescaled by subtracting the minimum from each value and multiplying by the new range, and dividing by the current range, and adding the new minimum (which acts as an offset). Missing values remain missing. See Feature scaling (Wikipedia)
Examples
df <- df |> rescale_min_max(c("x1", "x2", "x3"))
#> [1] "Rescaled vars to range from 0 to 1:"
#> [1] "x1" "x2" "x3"