This function normalizes a numeric or integer vector using one of two methods: min-max normalization (scales data to the range (0, 1)) or z-score normalization (centers data around 0 with a standard deviation of 1).
Usage
normalize(x, method = c("min_max", "z_score"))
Examples
# Example data
data <- c(10, 20, 30, 40, 50, NA)
# Min-max normalization
normalize(data, method = "min_max")
#> [1] 0.00 0.25 0.50 0.75 1.00 NA
# Z-score normalization
normalize(data, method = "z_score")
#> [1] -1.2649111 -0.6324555 0.0000000 0.6324555 1.2649111 NA
# Default behavior (min-max normalization)
normalize(data)
#> ℹ As no method was supplied, `normalize()` will default to min-max normalization methods.
#> [1] 0.00 0.25 0.50 0.75 1.00 NA