Usage
scale_numeric(x, xmin = min(x, na.rm = TRUE), xmax = max(x, na.rm = TRUE))
Arguments
- x
the numeric vector to scale
- xmin
the minimum value used for the scaling. all all x < xmin are set to 0
- xmax
the maximum value used for the scaling. all x > xmax set to 1
Value
a numeric vector of the same length as x, with all values between 0 and 1, except for NAs which are unchanged
Examples
x <- c(0.1, 100, -2.5, 20, 78.2, NA)
scaled <- scale_numeric(x)
all(is.na(scaled) | (scaled >= 0 & scaled <= 1))
#> [1] TRUE