rowSums | R Documentation |
Calculates the sum for each row (column) of a matrix-like object.
rowSums(x, na.rm = FALSE, dims = 1, ...)
colSums(x, na.rm = FALSE, dims = 1, ...)
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. |
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).
Returns a numeric
vector
of length N (K).
base::colSums
for the default
rowSums
and colSums
methods.
Matrix::colSums
in the Matrix package
for rowSums
and colSums
methods defined for
CsparseMatrix derivatives (e.g. dgCMatrix objects).
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.