scaleXY: Rescale Data To Given Minimum- And Maxiumum- Values

View source: R/scaleXY.R

scaleXYR Documentation

Rescale Data To Given Minimum- And Maxiumum- Values

Description

This function allows convenient rescaling of data in the sence that the range covered will be adjusted to user-specified values. Instead of fixed min and max values for the output it is also possible to fix 2 given quantiles for user-specified values (and rescale by linear transformation).

Usage

scaleXY(
  x,
  min = 0,
  max = NULL,
  q = c(0, 1),
  silent = FALSE,
  debug = FALSE,
  callFrom = NULL
)

Arguments

x

(numeric vector, matrix or data.frame) object to rescacle

min

(numeric) minimum value in output, if of length=2 and max not given/valid its 2nd value will be used as max

max

(numeric) maximum value in output, defaults to 1 if not specified or use 2nd value of min (if min of length=2)

q

(numeric, length=2) vector giving quantile values to be used for setting frame of normalization (defaults to lowest and highest values expected)

silent

(logical) suppress messages

debug

(logical) additional messages for debugging

callFrom

(character) allow easier tracking of messages produced

Value

This function returns a vector (or matrix) of rescaled data (in dimensions of input)

See Also

scale, normalizeThis, blockNormalize

Examples

## 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)
 

wrMisc documentation built on Nov. 18, 2026, 5:06 p.m.