linscale | R Documentation |
Apply minmax linear scaling to a vector.
linscale(x, minmax = NULL, rev = c(FALSE, TRUE))
x |
Input vector. |
minmax |
minmax must be a list with elements "mn", "mx", "mn.orig" and "mx.orig", where "mn" and "mx" refer to the target min and max, and the remaining two refer to the current vector min and max. By default mn=-1 and mx=1. mn.orig and mx.orig can be missing, unless the scaling is reversed. |
rev |
Reverse scaling back to original: TRUE or FALSE. |
Outputs a list with elements:
x
- Scaled vector.
minmax
- List with resulting mn, mx, mn.orig and mx.orig. Can be used as input to reverse scaling.
Nikolaos Kourentzes, nikolaos@kourentzes.com
y <- rnorm(20)*100
sc <- linscale(y)
x <- sc$x
print(c(min(y),max(y)))
print(c(min(x),max(x)))
sc.rev <- linscale(x,minmax=sc$minmax,rev=TRUE)
print(c(min(sc.rev$x),max(sc.rev$x)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.