The order()
function in R is used to return a permutation that simply orders or rearranges a sequence of numeric, complex, character, or logical vectors in ascending or descending order by their index positions.
order(…, na.last = TRUE, decreasing = FALSE)
The order()
function takes the following parameter values:
...
: This is a sequence of numeric, complex, character, or logical vectors of the same length to be ordered in ascending or descending order. This is a required parameter.na.last
: This takes a boolean value (TRUE
or FALSE
). If TRUE
, the missing value in the input data is put last. If FALSE
, they are removed first and NA
values are also removed. This is an optional parameter.decreasing
: This takes a boolean value indicating if the sort order should be in ascending (increasing) or descending (decreasing) order. This is an optional parameter.# creating a numerical objecta <- c(100, 5, 2, 8, 10, 1, 0.5)# sorting increasinglyorder(a, decreasing=TRUE)# sorting decreasignlyorder(a, decreasing = FALSE)
a
.order()
function.order()
function.