colOrder: Column and row-wise Order - Sort Indices

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/Order.R

Description

Column and row-wise Order - Sort Indices.

Usage

1
2
3
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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

Example output

Loading required package: Rcpp
Loading required package: RcppZiggurat
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    1   10    6    2    9    3    8    5    4     7
 [2,]    1    5    2    4    8    3    6   10    7     9
 [3,]    7    8    4    3    2    9   10    1    6     5
 [4,]    6    4    7    9   10    2    5    8    3     1
 [5,]    7    8   10    3    9    6    2    1    4     5
 [6,]    2    7    8    9    6    4    3   10    1     5
 [7,]    2    3    4    1    7    6    5   10    8     9
 [8,]    4    5   10    3    9    6    7    8    2     1
 [9,]    1    6    7    3    9    5    8    2    4    10
[10,]    9    4    8    7    3    6   10    2    5     1
[1] TRUE
[1] TRUE

Rfast documentation built on May 18, 2021, 1:07 a.m.