Learn R Programming

berryFunctions (version 1.22.5)

rescale: shift and scale a vector

Description

rescale a numeric vector: map values linearly onto a given range

Usage

rescale(x, from = 0, to = 1)

Value

numeric vector, rescaled onto output range

Arguments

x

Numerical vector of values to be mapped to a given range

from

output minimum. DEFAULT: 0

to

output maximum. DEFAULT: 1

Author

Berry Boessenkool, berry-b@gmx.de, Jan 2016

References

https://stackoverflow.com/a/18303620

See Also

Examples

Run this code

rescale(10:15, 135, 200)
rescale(10:15, 200, 135)
rescale(10:15, to=c(1,5))

values <- rbeta(1e3, shape1=4, shape2=35)
hist(rescale(values, 135, 200), breaks=25, col=3)

Run the code above in your browser using DataLab