Column and row-wise Order - Sort Indices | R Documentation |
Column and row-wise Order - Sort Indices.
colOrder(x,stable=FALSE,descending=FALSE, parallel = FALSE, cores = 0)
rowOrder(x,stable=FALSE,descending=FALSE, parallel = FALSE, cores = 0)
Order(x,stable=FALSE,descending=FALSE,partial = NULL,parallel = FALSE)
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. For Order, this argument is supported on Windows and most of the unix. |
partial |
A boolean value for partial sorting. |
cores |
Number of cores to use for parallelism. Valid only when argument parallel is set to TRUE column - major ordering. Default value is 0 and it means the maximum supported cores. |
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.
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".
Manos Papadakis
R implementation and documentation: Manos Papadakis <papadakm95@gmail.com>.
colsums, coldiffs, colMedians, colprods
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.