sort(x, decreasing = FALSE, ...) sort.int(x, partial = NULL, na.last = NA, decreasing = FALSE, method = c("shell", "quick"), index.return = FALSE) ## Default S3 method: sort(x, decreasing = FALSE, na.last = NA, ...) ## S3 method for class 'POSIXlt': sort(x, decreasing = FALSE, na.last = NA, ...)
x | a numeric or character vector. Infinite values (Inf) are allowed in numeric vectors. Missing values (NAs) are allowed in the input vector, but the default behavior deletes any missing values. |
decreasing | a logical value. If TRUE, the elements have a descending sort order. If FALSE (the default), the elements have an ascending order. |
partial | a vector of indices into data for partial sorting. If partial has a positive length, only the elements named in partial are guaranteed to be in their proper positions after the sort. All other elements are in their proper gaps between the partial elements, but not necessarily in the proper order within the gaps. |
na.last |
a vector of length 1 that specifies how to handle missing values
(NAs).
The possible values and results are:
|
method | specifies the sort algorithm. By default, when index.return = TRUE, the vector is sorted using a stable sort algorithm. If you specify method = "quick", it uses an unstable (and faster) sort algorithm. If you specify any other method, the default sort algorithm is employed. In particular, the "shell" method is present only for R compatibility, and does not imply using shell sort. |
index.return | a logical value. If TRUE, the return value is a list that contains both the sorted vector and an ordering vector. By default, when index.return = TRUE the input vector is sorted using a stable sort algorithm , however, if you specify method = "quick" then an unstable (and faster) sort algorithm is used. |
... | additional arguments passed to the generic method. |
mydata <- c(2, 9, 18, NA, 3, 2) # create sample object sort(mydata) # missing values are deleted sort(mydata, na.last = TRUE) # put missing values at the end sort(mydata, index.return = TRUE) sort(sample(1:100, 50), decreasing = TRUE, method = "quick") sort(sample(1:100, 50), partial = c(20, 30))## POSIXlt (plt <- as.POSIXlt("1970-1-1") + c(NA, 1:3)) sort(plt, decreasing = TRUE, na.last = TRUE)