scale_to_range: Scale Numeric Vector to a Given Range

View source: R/vectors.R

scale_to_rangeR Documentation

Scale Numeric Vector to a Given Range

Description

Scale Numeric Vector to a Given Range

Usage

scale_to_range(x, min = 0, max = 1, ...)

Arguments

x

Numeric vector

min

Optional. Desired new minimum value. Defaults to 0.

max

Optional. Desired new maximum value. Defaults to 1.

...

Optional. Passed on to min() and max() functions internally. If vector contains missing values, may want to specify na.rm = TRUE.

Value

Numeric vector with minimum value of min and maximum value of max.

Examples

# Simple numeric vector:
x <- c(-2, 0, 4)

# Scale to the c(0, 1) range:
scale_to_range(x)

# Leave minimum value untouched:
scale_to_range(x, min = -2, max = 1)

stopsack/khsmisc documentation built on Sept. 22, 2023, 12:26 p.m.