Learn R Programming

DescTools (version 0.99.19)

LinScale: Linear Scaling

Description

This will scale the numeric vector x linearly from an old scale between low and high to a new one between newlow and newhigh.

Usage

LinScale(x, low = NULL, high = NULL, newlow = 0, newhigh = 1)

Arguments

x
a numeric matrix(like object).

low
numeric. The minimum value of the scale, defaults to min(x). This is calculated columnwise by default; defined low or high arguments will be recycled if necessary.
high
numeric. The maximum value of the scale, defaults to max(x). This is calculated columnwise by default; when a maxval is entered, it will be recycled.
newlow
numeric. The minimum value of the new scale, defaults to 0, resulting in a 0-1 scale for x. newlow is recycled if necessary.
newhigh
numeric. The maximum value of the scale, defaults to 1. newhigh is recycled if necessary.

Value

scaled:center" and "scaled:scale"

Details

Hmm, hardly worth coding...

See Also

scale, RobScale, sweep

Examples

Run this code
# transform the temperature from Celsius to Fahrenheit
LinScale(d.pizza[1:20, "temperature"], 0, 100, -17.8, 37.8 )

# and the price from Dollar to Euro
LinScale(d.pizza[1:20, "price"], 0, 1, 0, 0.76)

# together
LinScale(d.pizza[1:20, c("temperature", "price")],
  0, c(100, 1), c(-17.8, 0), c(37.8, 0.76) )


## Not run: 
# par(mfrow=c(3,1), mar=c(0,5,0,3), oma=c(5,0,5,0))
# plot(LinScale(d.frm[,1]), ylim=c(-2,2), xaxt="n", ylab="LinScale")
# plot(RobScale(d.frm[,1]), ylim=c(-2,2), xaxt="n", ylab="RobScale")
# plot(scale(d.frm[,1]), ylim=c(-2,2), ylab="scale")
# title("Compare scales", outer = TRUE)
# ## End(Not run)

Run the code above in your browser using DataLab