## simple vector
scale(11:19) # standardizes (base R), is not 'rescaling'
scaleXY(11:19) # range form 0 to 1
scaleXY(11:19, min=1, max=10)
scaleXY(11:19, c(1, 10)) # min & max as single argument
# rescale matrix with NA
## rescale to 20th and 80th quantile (ie other than min or max)
scaleXY(11:19, min=1, max=10, q=c(0.2, 0.8))
## rescale matrix with NA
mat1 <- matrix(11:20, ncol=2, dimnames=list(letters[1:5], c("A","B")))
mat1[2,1] <- NA
scaleXY(mat1)
scaleXY(mat1, min=1, max=10, q=c(0.2, 0.8))
## rescale for each column individually
dat2 <- apply(mat1, 2, scaleXY, 1, 100)
range(dat2)
summary(dat2)
Run the code above in your browser using DataLab