Row-standardize a matrix; safe for zero row-sums.

row_standardize(C, warn = FALSE, msg = "Row standardizing connectivity matrix")

Arguments

C

A matrix

warn

Print message msg if warn = TRUE.

msg

A warning message; used internally by geostan.

Value

A row-standardized matrix, W (i.e., all row sums equal 1, or zero).

Examples

A <- shape2mat(georgia)
head(Matrix::summary(A))
Matrix::rowSums(A)

W <- row_standardize(A)
head(Matrix::summary(W))
Matrix::rowSums(W)