rescale {plotrix} | R Documentation |
Scale a vector or matrix of numbers into a new range.
rescale(x,newrange)
x |
A numeric vector, matrix or data frame. |
newrange |
The minimum and maximum value of the range into which
x will be scaled. |
rescale
performs a simple linear conversion of x
into the
range specified by newrange
. Only numeric vectors, matrices or data
frames with some variation will be accepted. NAs are now preserved -
formerly the function would fail.
On success, the rescaled object, otherwise the original object.
Jim Lemon
# 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,xlab="X values",type="h") lines(seq(-3,3,length=100),normal.density)