normalize: Normalizes numeric data to a given scale.

View source: R/normalize.R

normalizeR Documentation

Normalizes numeric data to a given scale.

Description

Currently implemented for numeric vectors, numeric matrices and data.frame. For matrixes one can operate on rows or columns For data.frames, only the numeric columns are touched, all others are left unchanged. For constant vectors / rows / columns most methods fail, special behaviour for this case is implemented.

The method also handles NAs in in x and leaves them untouched.

Usage

normalize(
  x,
  method = "standardize",
  range = c(0, 1),
  margin = 1L,
  on.constant = "quiet"
)

Arguments

x

[numeric | matrix | data.frame]
Input vector.

method

[character(1)]
Normalizing method. Available are:
“center”: Subtract mean.
“scale”: Divide by standard deviation.
“standardize”: Center and scale.
“range”: Scale to a given range.

range

[numeric(2)]
Range for method “range”. The first value represents the replacement for the min value, the second is the substitute for the max value. So it is possible to reverse the order by giving range = c(1,0). Default is c(0,1).

margin

[integer(1)]
1 = rows, 2 = cols. Same is in apply Default is 1.

on.constant

[character(1)]
How should constant vectors be treated? Only used, of “method != center”, since this methods does not fail for constant vectors. Possible actions are:
“quiet”: Depending on the method, treat them quietly:
“scale”: No division by standard deviation is done, input values. will be returned untouched.
“standardize”: Only the mean is subtracted, no division is done.
“range”: All values are mapped to the mean of the given range.
“warn”: Same behaviour as “quiet”, but print a warning message.
“stop”: Stop with an error.

Value

[numeric | matrix | data.frame].

See Also

scale


BBmisc documentation built on Sept. 29, 2022, 5:12 p.m.

Related to normalize in BBmisc...