⚠️There's a newer version (1.3.0) of this package. Take me there.

matrixStats: Functions that Apply to Rows and Columns of Matrices (and to Vectors)

The matrixStats package provides highly optimized functions for computing common summaries over rows and columns of matrices, e.g. rowQuantiles(). There are also functions that operate on vectors, e.g. logSumExp(). Their implementations strive to minimize both memory usage and processing time. They are often remarkably faster compared to good old apply() solutions. The calculations are mostly implemented in C, which allow us to optimize beyond what is possible to do in plain R. The package installs out-of-the-box on all common operating systems, including Linux, OS X and Windows.

Example

With a matrix

> X <- matrix(rnorm(20 * 500), nrow = 20, ncol = 500)

it is many times faster to calculate medians column by column using

> mu <- matrixStats::colMedians(X)

than using

> mu <- apply(X, MARGIN=2, FUN=median)

Moreover, if performing calculations on a subset of rows and/or columns, using

> mu <- colMedians(X, rows=33:158, cols=1001:3000)

is much faster and more memory efficient than

> mu <- apply(X[33:158,1001:3000], MARGIN=2, FUN=median)

Benchmarks

For formal benchmarking of matrixStats functions relative to alternatives, see the Benchmark reports.

Installation

R package matrixStats is available on CRAN and can be installed in R as:

install.packages('matrixStats')

Software status

Resource:CRANTravis CIAppveyor
Platforms:MultipleLinuxWindows
R CMD check
Test coverage

Copy Link

Version

Down Chevron

Install

install.packages('matrixStats')

Monthly Downloads

189,035

Version

0.50.2

License

Artistic-2.0

Issues

Pull Requests

Stars

Forks

Last Published

April 24th, 2016

Functions in matrixStats (0.50.2)