normalize_rows: Normalize rows to sum to one

normalize_rowsR Documentation

Normalize rows to sum to one

Description

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

Usage

normalize_rows(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), rows with norm zero are left as-is. If this is TRUE, an error will be thrown instead.

Value

the row-normalized matrix (except for any zero rows)

See Also

normalize_cols


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