colOrder: Column and row-wise Order - Sort Indices

View source: R/Order.R

Column and row-wise Order - Sort IndicesR Documentation

Column and row-wise Order - Sort Indices

Description

Column and row-wise Order - Sort Indices.

Usage

colOrder(x,stable=FALSE,descending=FALSE, parallel = FALSE)
rowOrder(x,stable=FALSE,descending=FALSE, parallel = FALSE)
Order(x,stable=FALSE,descending=FALSE,partial = NULL)

Arguments

x

A matrix with numbers or a numeric/character vector.

stable

A boolean value for using a stable sorting algorithm.

descending

A boolean value (TRUE/FALSE) for sorting the vector in descending order. By default sorts the vector in ascending.

parallel

A boolean value for parallel version.

partial

A boolean value for partial sorting.

Details

The function applies "order" in a column or row-wise fashion or Order a vector. If you want the same results as R's, then set "stable=TRUE" because "stable=FALSE" uses a sorting algorithm that it is not stable like R's sort. But it is faster to use the default. This verion is faster for large data, more than 300.

Value

For "colOrder" and "rowOrder" a matrix with integer numbers. The result is the same as apply(x, 2, order) or apply(x, 1, order).

For "Order" sort the vector and returns the indices of each element that it has before the sorting. The result is the same as order(x) but for the same exactly results set argument "stable" to "TRUE".

Author(s)

Manos Papadakis

R implementation and documentation: Manos Papadakis <papadakm95@gmail.com>.

See Also

colsums, coldiffs, colMedians, colprods

Examples

x <- matrix( runif(10 * 10), ncol = 10 )
res<-colOrder(x)
res<-apply(x, 2, order)
res<-rowOrder(x)
t(apply(x, 1, order))

y <- rnorm(100)
b <- Order(y)
a <- order(y)
all.equal(a,b) ## false because it is not stable
b <- Order(y,stable=TRUE)
all.equal(a,b) ## true because it is stable

x<-y<-b<-a<-NULL

Rfast documentation built on March 18, 2022, 7:41 p.m.