normalize: Normalize a Vector or Matrix

View source: R/normalize.R

normalizeR Documentation

Normalize a Vector or Matrix

Description

Normalizes a vector or each record of a matrix into a simplex.

Usage

normalize(x)

Arguments

x

Numeric vector or matrix. If vector, then the vector will be normalized to sum to one. If matrix, then each record will be normalized to sum to one (and a matrix returned).

Details

Returns a vector or matrix whose elements (if vector) or records (if matrix) are computed as ⁠x/⁠sum(x). This normalizes a vector or matrix record into a set of proportions which sum to one (i.e., a simplex). If a matrix is provided for the x argument, then normalization is performed independently for each record.

Value

A numeric vector or matrix whose elements (if vector) or records (if matrix) sum to one.

See Also

softmax for the softmax function.

Examples

# Normalize vector.
normalize(x=c(3,1,5,7))

LocaTT documentation built on June 14, 2026, 1:06 a.m.