Sort - Integer Sort - Sort a vector coresponding to another | R Documentation |
Fast sorting a vector.
Sort(x,descending=FALSE,partial=NULL,stable=FALSE,na.last=NULL,parallel = FALSE)
Sort.int(x)
sort_cor_vectors(x, base, stable = FALSE, descending = FALSE)
x |
A numerical/integer/character vector with data. |
base |
A numerical/character vector to help sorting the x. |
descending |
A boolean value (TRUE/FALSE) for sorting the vector in descending order. By default sorts the vector in ascending. |
partial |
This argument has two usages. The first is an index number for sorting partial the vector. The second is a vector with 2 values, start and end c(start,end). Gives you a vector where the elements between start and end will be sorted only. Not character vector. |
stable |
A boolean value (TRUE/FALSE) for choosing a stable sort algorithm. Stable means that discriminates on the same elements. Not character vector. |
na.last |
Accept 4 values. TRUE, FALSE, NA, NULL. TRUE/FALSE: for put NAs last or first. NA: for remove NAs completely from vector. NULL: by default. Leave it like that if there is no NA values. |
parallel |
Do you want to do it in parallel, in C++? TRUE or FALSE. (Supported on Windows and most of the unix) |
This function uses the sorting algorithm from C++. The implementation is very fast and highly optimised. Especially for large data.
Sort and Sort.int: The sorted vector.
sort_cor_vectors: The first argument but sorted acording to the second.
Manos Papadakis
R implementation and documentation: Manos Papadakis <papadakm95@gmail.com>.
nth, colnth, rownth,sort_unique, Round
x <- rnorm(1000)
s1 <- Sort(x)
s2 <- sort(x)
all.equal(s1,s2) #true but not if many duplicates.
s1 <- Sort(x,partial=100)
s2 <- sort(x,partial=100)
all.equal(s1,s2) #true
s1 <- Sort(x,stable=TRUE)
s2 <- sort(x)
all.equal(s1,s2) #true
x <- as.character(x)
s1 <- Sort(x)
s2 <- sort(x)
all.equal(s1,s2) #true
y <- runif(1000)
b <- sort_cor_vectors(x,y)
x<-rpois(100,100)
all.equal(Sort.int(x),sort.int(x))
x<-y<-y<-s1<-s2<-NULL
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.