scaleToUnit: Scale to unit range.

scaleToUnitR Documentation

Scale to unit range.

Description

scaleToUnit scales the columns of a numeric matrix to the unit range.

Usage

scaleToUnit(x, min = 0, 
    max = 1, center = TRUE, 
    solveSingular = TRUE)

Arguments

x

a numeric matrix

min

the minimum in each dimension to scale to (defaults to 0)

max

the maximum in each dimension to scale to (defaults to 1)

center

shift and scale values to fit in the desired interval, or only scale them (and keep the mean fixed)?

solveSingular

if TRUE, constant columns will be transformed to the mean of min and max, not to NaN, as would result from a straighforward implementation

Value

Scaled x. The desired minimum and maximum values are returned as attributes min and max, respectively. The minimum/maximum values of x are returned as attributes min_x and max_x, respectively. The function used to transform a row in x to the desired range is returned as the tx attribute. The inverse transform can be find in the txInv attribute.

Author(s)

Tomas Sieger

Examples


# scale the \code{iris} data set
x <- iris[, 1:4]
summary(x)
x2 <- scaleToUnit(x)
summary(x2)

# transform explicitly:
x2[1, ]
attr(x2, 'tx')(iris[1, 1:4])

# inverse transform:
y <- cbind(1:4,1)
y
y2 <- scaleToUnit(y ,min = 0, max = 1)
y2
y3 <- attr(y2, 'txInv')(y2)
y3

# scale, but not center
scaleToUnit(1:10, min = -1, max = 1, center = FALSE)
scaleToUnit(-2:5, min = -1, max = 1, center = FALSE)



tsieger/tsiMisc documentation built on Oct. 10, 2023, 10:24 p.m.