rowSums: Calculates the sum for each row (column) of a matrix-like...

rowSumsR 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 TRUE, missing values (NA or NaN) are omitted from the calculations.

dims

A single integer indicating which dimensions are regarded as rows or columns to sum over. For rowSums, the sum is over dimensions dims+1, ...; for colSums it is over dimensions 1:dims.

...

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::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).

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)

Bioconductor/MatrixGenerics documentation built on Nov. 2, 2024, 4:13 a.m.