This function scales and translates the values in the input vector x
such that the minimum value becomes 0 and the maximum value becomes 1.
The normalization is done by first subtracting the minimum value
from each element (translation) and then dividing each element by
the new maximum value (scaling).
Arguments
- x
A numeric vector that needs to be normalized to the 0-1 range. IF x
is a matrix, the normalization is applied column-wise.
Value
A numeric vector with values normalized to the 0-1 range. If x
is a matrix, the function returns a matrix with columns normalized to the 0-1 range.
Examples
# Generate random values
x <- rnorm(100)
range(x)
#> [1] -1.900061 2.564408
normed_x <- norm01(x)
range(normed_x) # This should show values between 0 and 1
#> [1] 0 1