internal function: xscale

xscale(x, torange, xrange = c(min(x), max(x)))

Arguments

x

numeric vector to be transformed

torange

new range

xrange

optional. full range of x vector if you are scaling only part of it. calculated from x if not supplied.

Value

transformed numeric vector

Details

Linear transformation to map x to a new range, so min(x)==xrange[1], and max(x)==xrange[2]

Examples

x<-1:10 cbind(x, GUESSFM:::xscale(x,c(0.1,1)), GUESSFM:::xscale(x,c(1319,20578)))
#> x #> [1,] 1 0.1 1319.000 #> [2,] 2 0.2 3458.889 #> [3,] 3 0.3 5598.778 #> [4,] 4 0.4 7738.667 #> [5,] 5 0.5 9878.556 #> [6,] 6 0.6 12018.444 #> [7,] 7 0.7 14158.333 #> [8,] 8 0.8 16298.222 #> [9,] 9 0.9 18438.111 #> [10,] 10 1.0 20578.000
## Now use only part of x x<-x[2:7] ## WRONG cbind(x, GUESSFM:::xscale(x,c(0.1,1)), GUESSFM:::xscale(x,c(1319,20578)))
#> x #> [1,] 2 0.10 1319.0 #> [2,] 3 0.28 5170.8 #> [3,] 4 0.46 9022.6 #> [4,] 5 0.64 12874.4 #> [5,] 6 0.82 16726.2 #> [6,] 7 1.00 20578.0
## RIGHT cbind(x, GUESSFM:::xscale(x,c(0.1,1),xrange=c(1,10)), GUESSFM:::xscale(x,c(1319,20578),xrange=c(1,10)))
#> x #> [1,] 2 0.2 3458.889 #> [2,] 3 0.3 5598.778 #> [3,] 4 0.4 7738.667 #> [4,] 5 0.5 9878.556 #> [5,] 6 0.6 12018.444 #> [6,] 7 0.7 14158.333