prep.transform: Transformation

Description Usage Arguments Value Examples

View source: R/prep.R

Description

Transforms values from using any mathematical function (e.g. log).

Usage

1

Arguments

data

a matrix with data values

fun

reference to a transformation function, e.g. 'log' or 'function(x) x^2'.

...

optional parameters for the transformation function

Value

data matrix with transformed values

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# generate a matrix with two columns
y <- cbind(rnorm(100, 10, 1), rnorm(100, 20, 2))

# apply log transformation
py1 = prep.transform(y, log)

# apply power transformation
py2 = prep.transform(y, function(x) x^-1.25)

# show distributions
par(mfrow = c(2, 3))
for (i in 1:2) {
   hist(y[, i], main = paste0("Original values, column #", i))
   hist(py1[, i], main = paste0("Log-transformed, column #", i))
   hist(py2[, i], main = paste0("Power-transformed, column #", i))
}

mdatools documentation built on Sept. 13, 2021, 9:07 a.m.