| rowSums {MatrixGenerics} | R Documentation |
Calculates the sum for each row (column) of a matrix-like object
Description
Calculates the sum for each row (column) of a matrix-like object.
Usage
rowSums(x, na.rm = FALSE, dims = 1, ...)
colSums(x, na.rm = FALSE, dims = 1, ...)
Arguments
x |
An NxK matrix-like object, a numeric data frame, or an array-like object of two or more dimensions. |
na.rm |
If |
dims |
A single integer indicating which dimensions are regarded
as rows or columns to sum over. For |
... |
Additional arguments passed to specific methods. |
Details
This man page documents the rowSums and colSums
S4 generic functions defined in the MatrixGenerics package.
See ?base::colSums for the default methods (defined
in the base package).
Value
Returns a numeric vector of length N (K).
See Also
-
base::colSumsfor the defaultrowSumsandcolSumsmethods. -
Matrix::colSumsin the Matrix package forrowSumsandcolSumsmethods defined for CsparseMatrix derivatives (e.g. dgCMatrix objects).
Examples
mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0
print(mat)
rowSums(mat)
colSums(mat)