normalize_cols: Normalize columns to sum to one

normalize_colsR Documentation

Normalize columns to sum to one

Description

A convenience function for a frequent operation of normalizing the columns of a matrix. The typical application in document modeling is to to ensure that the columns sum to one (L1 normalization). Sometimes it is convenient instead to set the columns to have a unit Euclidean norm (L2 normalization).

Usage

normalize_cols(x, norm = "L1", stopzero = FALSE)

Arguments

x

a matrix or Matrix

norm

Either "L1", the default (the sum of the absolute value of weights), or "L2", the Euclidean norm

stopzero

If FALSE (the default), columns with norm zero are left as-is. If this is TRUE, an error will be thrown instead.

Value

the column-normalized matrix (except for any zero columns)

See Also

normalize_cols


agoldst/dfrtopics documentation built on July 15, 2022, 4:13 p.m.