Learn R Programming

Morpho (version 2.1)

meanMat: fast calculation of a Matrix' per row/ per column mean - useful for very large matrices

Description

fast calculation of a Matrix' per row/ per column mean - equivalent to apply(X,2,mean) or apply(X,1,mean)- useful for very large matrices

Usage

meanMat(A, usedim = 2)

Arguments

A
numeric matrix
usedim
integer: select over which dimension to average

Value

  • vector containing row/column mean

Examples

Run this code
A <- matrix(rnorm(1e6),1000,1000)
b <- meanMat(A)
# same as apply(A,2,mean)
b1 <- meanMat(A,1)
# same as apply(A,1,mean)
#compare timing
system.time(meanMat(A))
system.time(apply(A,2,mean))

Run the code above in your browser using DataLab