Data checks - Check if object is ordered
is_sorted.RdThis function is a wrapper around is.unsorted() to check if a vector is
sorted in ascending or descending order.
Arguments
- x
[
atomic] An atomic vector to test.- order
[
"asc"|"desc"] The order to check for:"asc"for ascending,"desc"for descending.- na.rm
[
TRUE|FALSE] IfTRUE,NAvalues are removed before checking for order. IfFALSE,NAvalues propagate and imply in anNAresult.- strictly
[
TRUE|FALSE] IfTRUE, the function checks for strict order, meaning that no two elements can be equal.
Value
[TRUE | FALSE | NA] The scalar result of the test.. If na.rm = TRUE, the result is
always TRUE or FALSE.
Examples
# Control the order of the check with `order` argument
is_sorted(1:5) #> TRUE
#> [1] TRUE
is_sorted(1:5, order = "desc") #> FALSE
#> [1] FALSE
# Control the handling of NA values with `na.rm` argument:
is_sorted(c(1, 2, NA, 4), na.rm = TRUE) #> TRUE
#> [1] TRUE
# Control the strictness of the order with `strictly` argument:
is_sorted(c(1, 2, 2, 4), strictly = TRUE) #> FALSE
#> [1] FALSE