Learn R Programming

convergenceDFM (version 0.1.4)

row_norm1: Normalize matrix rows to sum to one

Description

Scales each row of a matrix so that its elements sum to 1. Handles zero-sum rows by leaving them unchanged (avoiding division by zero).

Usage

row_norm1(M)

Value

Matrix of the same dimensions as M with each row summing to 1 (except rows that originally summed to zero).

Arguments

M

Numeric matrix to be row-normalized.

Examples

Run this code
# \donttest{
M <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2)
M_norm <- row_norm1(M)
rowSums(M_norm)  # Should be c(1, 1)
# }

Run the code above in your browser using DataLab