rowMeans | R Documentation |
Calculates the mean for each row (column) of a matrix-like object.
rowMeans(x, na.rm = FALSE, dims = 1, ...)
colMeans(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 mean over. For |
... |
Additional arguments passed to specific methods. |
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).
Returns a numeric
vector
of length N (K).
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).
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.