Learn R Programming

Rfast (version 1.2)

Sorting of the columns of a matrix (in parallel): Sorting of the columns of a matrix (in parallel).

Description

Fast sorting of the columns of a matrix (in parallel).

Usage

sort_mat(x)
sort_mat_parallel(x, ncores)

Arguments

x
A numerical matrix with data.
ncores
The number of cores to use.

Value

The matrix with its columns independently sorted.

See Also

nth, colMaxs, colMins

Examples

Run this code
x <- matrix( rnorm(1000 * 20), ncol = 20 )
system.time( sort_mat(x) )
system.time( sort_mat_parallel(x, 2) )
system.time( apply(x, 2, sort)  )
s1 <- sort_mat_parallel(x, 2)
s2 <- apply(x, 2, sort) 
all.equal(as.vector(s1), as.vector(s2))

Run the code above in your browser using DataLab