Scale Numeric Vector to a Given Range
scale_to_range(x, min = 0, max = 1, ...)
Numeric vector with minimum value of min
and
maximum value of max
.
# Simple numeric vector:
x <- c(-2, 0, 4)
# Scale to the c(0, 1) range:
scale_to_range(x)
#> [1] 0.0000000 0.3333333 1.0000000
# Leave minimum value untouched:
scale_to_range(x, min = -2, max = 1)
#> [1] -2 -1 1