Learn R Programming

zoocat (version 0.2.0.1)

normalize: Normalize data

Description

Normalize each column of the object using different methods. See details.

Usage

normalize(x, ...)

# S3 method for default normalize(x, method = "sd1", base.period = 1:nrow(x), ...)

# S3 method for zoo normalize(x, method = "sd1", base.period = index(x), ...)

Arguments

x

a vector, matrix, data frame or zoo object.

...

additional arguments to be passed to or from methods.

method

a character string indicating which method to use. Must be 'sd1'(default), 'anomaly' or 'perc'. See details.

base.period

a vector indicating the index or range of the base period. If NULL, base period is the all index range. For matrix, base.period means the row numbers.

Details

Three methods for normalization can be used:

  1. "anomaly": Each column is normalized by \(x - \mu\), where \(\mu\) is the mean value based on the base.period.

  2. "perc": Each column is normalized by \(100 (x - \mu) / \mu\). This is often called anomaly percentage.

  3. "sd1": Each column is normalized by \((x - \mu) / \sigma\), where \(\sigma\) is the standard deviation based on the base.period. The standard deviations of the results will be 1 if the base.period is set to be the whole time range.

Examples

Run this code
# NOT RUN {
x <- matrix(1 : 20, nrow = 10)
colnames(x) <- c('a', 'b')
rownames(x) <- 1 : 10
normalize(x, method = 'anomaly')
normalize(x, method = 'perc')
normalize(x, method = 'sd1')

z <- zoo(x, order.by = 1991 : 2010)
normalize(z)

x <- matrix(1 : 20, nrow = 5)
colAttr <- data.frame(month = c(2, 3, 5, 6), name = c(rep('xxx', 3), 'yyy'))
zc <- zoocat(x, order.by = 1991 : 1995, colattr = colAttr)
normalize(zc)

# }

Run the code above in your browser using DataLab