Skip to contents

This function normalizes numerical values into a specified range, defaulting to the 0 to 1 range.

Usage

normalize(x, range = c(0, 1), ...)

Arguments

x

Numeric vector. The numbers to be normalized.

range

A numeric vector of length 2 specifying the desired range for normalization. Default is c(0, 1).

...

Additional parameters.

Value

A numeric vector with normalized x values.

Examples

x <- c(0, 1, 4, 7.5, 10)
normalize(x)
#> [1] 0.00 0.10 0.40 0.75 1.00
normalize(x, range = c(-1, 1))
#> [1] -1.0 -0.8 -0.2  0.5  1.0