normalize: Centering and scaling of numeric data

View source: R/normalize.R

normalizeR Documentation

Centering and scaling of numeric data

Description

Methods to normalize numeric data with respect to mean and variance.

Usage

normalize(x, center = TRUE, scale = TRUE, ...)

## S3 method for class 'numeric'
normalize(x, center = TRUE, scale = TRUE, ...)

## S3 method for class 'matrix'
normalize(
  x,
  center = TRUE,
  scale = TRUE,
  byrow = FALSE,
  ignore = integer(),
  jointly = list(),
  ...
)

## S3 method for class 'data.frame'
normalize(
  x,
  center = TRUE,
  scale = TRUE,
  byrow = FALSE,
  ignore = integer(),
  jointly = list(),
  ...
)

## S3 method for class 'list'
normalize(x, center = TRUE, scale = TRUE, ...)

Arguments

x

An object to be normalized.

center

[integer(1)]
Normalize to zero mean?

scale

[integer(1)]
Normalize to unit variance?

...

Further arguments to be passed to or from other methods.

byrow

[integer(1)]
Only relevant if x has two dimensions (rows and columns).

In this case, set to TRUE to normalize row-wise or FALSE to normalize column-wise (default).

ignore

[integer()]
Column indices (or row indices if byrow = TRUE) to not normalize.

jointly

[list()]
Disjoint column indices (or row indices if byrow = TRUE) to normalize jointly.

Value

The normalized input x with the centering and scaling values used (if any) added as attributes "center" and "scale".

Examples

# can normalize numeric vectors, matrices, data.frames, and lists of those
normalize(
  list(
    c(-3, 0, 3),
    matrix(1:12, nrow = 3, ncol = 4),
    data.frame(a = 1:3, b = 4:6, c = 7:9, d = 10:12)
  )
)

# can ignore columns (or rows)
normalize(
  data.frame(a = 1:3, b = c("A", "B", "C"), c = 7:9, d = 10:12),
  ignore = 2
)

# can normalize columns (or rows) jointly
normalize(
  matrix(1:12, nrow = 3, ncol = 4),
  jointly = list(1:2, 3:4)
)

normalize documentation built on June 8, 2025, 1:47 p.m.