Check If A Vector Is Ordered

Share:

Description

Performs check to determine if a vector is strictly increasing, strictly decreasing, not decreasing, or not increasing.

Usage

1
isOrdered(x, increasing = TRUE, strictly = TRUE)

Arguments

x

a numeric vector

increasing

test for increasing/decreasing values

strictly

are duplicates OK

Details

Designed for internal use with xts, this provides highly optimized tests for ordering.

Value

Logical

Author(s)

Jeffrey A. Ryan

See Also

is.unsorted

Examples

1
2
3
4
5
6
7
8
9
# strictly increasing
isOrdered(1:10, increasing=TRUE)
isOrdered(1:10, increasing=FALSE)
isOrdered(c(1,1:10), increasing=TRUE)
isOrdered(c(1,1:10), increasing=TRUE, strictly=FALSE)

# decreasing
isOrdered(10:1, increasing=TRUE)
isOrdered(10:1, increasing=FALSE)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.