Skip to contents

Rescale numeric vector

Usage

rescale(x, from = range(x, na.rm = TRUE, finite = TRUE), to = c(0, 1))

Arguments

x

A numeric vector.

from

The range of the original data.

to

The range of the rescaled data.

Value

A numeric vector with rescaled values.

Examples

x <- rnorm(10)
rescale(x)
#>  [1] 0.7408067 0.8957610 0.0000000 0.4009836 0.4287677 0.9369004 0.7894397
#>  [8] 0.6692964 0.3465121 1.0000000
rescale(x, from = c(0, 1))
#>  [1]  0.28739300  0.77337681 -2.03600252 -0.77839585 -0.69125642  0.90240246
#>  [7]  0.43992096  0.06311488 -0.94923493  1.10030204
rescale(x, to = c(0, 2))
#>  [1] 1.4816135 1.7915220 0.0000000 0.8019672 0.8575354 1.8738008 1.5788795
#>  [8] 1.3385928 0.6930243 2.0000000