rowcolSumSq {ramwas} | R Documentation |
Form row and column sums of squares for numeric matrices.
The functions are introduced as faster analogs of
rowSums(x^2)
and colSums(x^2)
calls.
rowSumsSq(x) colSumsSq(x)
x |
Numeric matrix. |
The function is implemented in C for better performance.
Return a vector of sums of values in each row/column for matrix
x
(rowSumsSq
/colSumsSq
).
Andrey A Shabalin andrey.shabalin@gmail.com
See rowSums
and colSums
for simple (not squared) row/column sums.
x = matrix( 1:99, 9, 11) # Calculate sums of squared elements in each row rsum2 = rowSumsSq(x) # Compare with alternative calculation stopifnot( all.equal( rsum2, rowSums(x^2) )) # Calculate sums of squared elements in each column csum2 = colSumsSq(x) # Compare with alternative calculation stopifnot( all.equal( csum2, colSums(x^2) ))