rowMeans: Calculates the mean for each row (column) of a matrix-like...

rowMeansR Documentation

Calculates the mean for each row (column) of a matrix-like object

Description

Calculates the mean for each row (column) of a matrix-like object.

Usage

rowMeans(x, na.rm = FALSE, dims = 1, ...)

colMeans(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 mean over. For rowMeans, the mean is over dimensions dims+1, ...; for colMeans it is over dimensions 1:dims.

...

Additional arguments passed to specific methods.

Details

This man page documents the rowMeans and colMeans S4 generic functions defined in the MatrixGenerics package. See ?base::colMeans for the default methods (defined in the base package).

Value

Returns a numeric vector of length N (K).

See Also

  • base::colMeans for the default rowMeans and colMeans methods.

  • Matrix::colMeans in the Matrix package for rowMeans and colMeans 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)

rowMeans(mat)
colMeans(mat)

Bioconductor/MatrixGenerics documentation built on April 19, 2024, 8:19 a.m.