[R] arbitrary scaling
Petr PIKAL
petr.pikal at precheza.cz
Mon Mar 8 15:37:54 CET 2010
Hi all
I know I probably reinvented wheel but it was maybe simpler then search in
docs or ask help before I did my part.
I made a simple function which can scale a vector between chosen values.
Do anybody know simpler/better approach?
myscale<-function(x, miny=0.5, maxy=1) {
rx <- diff(range(x, na.rm=T))
minx <- min(x, na.rm=T)
tga <- (maxy-miny)/rx
b <- miny - tga* minx
res <- x*tga+b
res
}
x <- c(5,30,50)
myscale(x)
[1] 0.5000000 0.7777778 1.0000000
Thank you
Regards
Petr
More information about the R-help
mailing list