Skip to contents

Scales a numeric vector to the range \([0,1]\) using min-max normalization. This is a special case of scRange.

Usage

minmax(x, na.rm = FALSE)

Arguments

x

Numeric vector. Input values to be scaled.

na.rm

Logical; if TRUE, ignore NAs when computing the range.

Value

A numeric vector of the same length as x, scaled to the range \([0,1]\).

Details

The scaled values are computed as: $$x_{scaled} = \frac{x - \min(x)}{\max(x) - \min(x)}$$

Equivalent to scRange(x, ra = c(0, 1)).

See also

scRange() for flexible output ranges.

Other NMR ++: .hotellingsT2()

Examples

x <- rnorm(20)
plot(x, type = 'l'); abline(h = range(x), lty = 2)
points(minmax(x), type = 'l', col = 'blue')
abline(h = c(0, 1), col = 'blue', lty = 2)