min_max_normalize | R Documentation |
Normalizes a numeric vector to a range of 0 to 1 using min-max scaling.
min_max_normalize(x, min_val = NULL, max_val = NULL)
x |
A numeric vector to be normalized. |
min_val |
Optional. The minimum value to use for normalization. If |
max_val |
Optional. The maximum value to use for normalization. If |
A numeric vector with values scaled between 0 and 1. If min_val
and max_val
are equal (or x
has no variance), returns a vector of 0.5s.
# Normalize a vector
x_vec <- c(10, 20, 30, 40, 50)
normalized_x <- min_max_normalize(x_vec)
print(normalized_x) # Should be 0, 0.25, 0.5, 0.75, 1
# Normalize with custom min/max
custom_normalized_x <- min_max_normalize(x_vec, min_val = 0, max_val = 100)
print(custom_normalized_x) # Should be 0.1, 0.2, 0.3, 0.4, 0.5
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.