Learn R Programming

Rfast (version 1.2)

Column-wise medians: Colum-wise medians (in parallel)

Description

Colum-wise medians of a matrix

Usage

colMedians(x)
colMedians_parallel(x, ncores)

Arguments

x
A matrix with the data.
ncores
How many cores to use.

Value

A vector with the column medians.

Details

The functions is written in C++ in order to be as fast as possible.

See Also

colVars, colMeans (buit-in R function)

Examples

Run this code
x <- matrix( rnorm(100 * 1000), ncol = 1000 )
system.time( apply(x, 2, median) )
system.time( colMedians(x) )
system.time( colMedians_parallel(x, ncores = 2) )
a <- apply(x, 2, median) 
b1 <- colMedians(x) 
b2 <- colMedians_parallel(x, ncores = 2)
all.equal(a, b1)
all.equal(a, b2)

Run the code above in your browser using DataLab