Learn R Programming

plotrix (version 1.41)

rescale: Scale a vector of numeric values into a new range.

Description

rescale performs a simple linear conversion of x into the range specified by newrange. Only numeric vectors with some variation will be accepted.

Usage

rescale(x,newrange)

Arguments

x
A numeric vector.
newrange
The minimum and maximum value of the range into which x will be scaled.

Value

  • On success, the rescaled vector.

Examples

Run this code
# scale one vector into the range of another
 normal.counts<-tabulate(cut(rnorm(100),breaks=seq(-3,3,by=1)))
 normal.density<-rescale(dnorm(seq(-3,3,length=100)),range(normal.counts))
 # now plot them
 plot(c(-2.5,-1.5,-0.5,0.5,1.5,2.5),normal.counts,type="h")
 lines(seq(-3,3,length=100),normal.density)

Run the code above in your browser using DataLab