matrixStats: Fast column- and row-wise versions of variance coded in C++

Description Usage Arguments Details Value Author(s) Examples

Description

These two functions are fast C++ versions for column- and row-wise variance calculation on matrices/data.frames and are meant to substitute the classical apply(mat, 1, var) approach.

Usage

1
2

Arguments

x

a matrix or data.frame

Details

They are coded in a way that they automatically remove NA values, so they behave like na.rm = TRUE.

Value

A vector with the variance values.

Author(s)

Andrej-Nikolai Spiess

Examples

1
2
3
4
5
6
7
8
9
## Speed comparison on large matrix.
## ~ 110x speed increase!
## Not run: 
MAT <- matrix(rnorm(10 * 500000), ncol = 10)
system.time(RES1 <- apply(MAT, 1, var))
system.time(RES2 <- rowVarsC(MAT))
all.equal(RES1, RES2)

## End(Not run)

propagate documentation built on May 7, 2018, 1:03 a.m.