Scale each row or column of a matrix by a numeric vector, equivalent to
left- or right-multiplying by a diagonal matrix.
rowscale computes diag(d) %*% X (row \(i\) scaled by
d[i]); colscale computes X %*% diag(d) (column
\(j\) scaled by d[j]).
Examples
m <- matrix(1:6, 2, 3)
rowscale(m, c(2, 0.5))
#> An amatrix dense matrix [cpu|policy=auto|precision=strict]
#> 2 x 3 Matrix of class "adgeMatrix"
#> [,1] [,2] [,3]
#> [1,] 2 6 10
#> [2,] 1 2 3
colscale(m, c(1, 2, 3))
#> An amatrix dense matrix [cpu|policy=auto|precision=strict]
#> 2 x 3 Matrix of class "adgeMatrix"
#> [,1] [,2] [,3]
#> [1,] 1 6 15
#> [2,] 2 8 18