rescale: Rescaling a numerical vector.

Description Usage Arguments Value Examples

Description

A function for rescaling a vector of integers or real numbers to an arbitrary interval. Element in the original vector with the minimum value will be transformed to a number deteremined by lower argument (zero by default), while the element with the maximum value will be transformed to a number deteremined by upper argument (one by default). All other elements will be rescaled proportionally.

Usage

1
rescale(x, lower = 0, upper = 1, na.rm = FALSE)

Arguments

x

A numeric vector where numbers need to be rescaled.

lower

Desired minimum value, by deafult set to 0.

upper

Desired maximum value, by deafult set to 1.

na.rm

A logical that indicates whether NA elements should be removed from the output or not. By default set to FALSE. Note that, if it is set to FALSE, the rescale will still remove NA's to do the computations, but it will simply leave the NA elements in the resulting vector.

Value

A numeric vector with rescaled elements from x.

Examples

1
2
3
4
5
6
7
8
# create some numeric vectors
x <- 1:10

# min element will be transformed to 0 and max element to 1
rescale(x)

# arbitrary lower and upper value
rescale(x, 20, 100)

hstojic/hfunk documentation built on May 17, 2019, 6:16 p.m.