powered by
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).
row_norm1(M)
Matrix of the same dimensions as M with each row summing to 1 (except rows that originally summed to zero).
M
Numeric matrix to be row-normalized.
# \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