ordering {ordering} | R Documentation |
ordering
Description
Determining the ordering (montonicity) of a vector
Usage
ordering(x, na.rm = TRUE)
monotonicity(x, na.rm = TRUE)
Arguments
x |
numeric vector |
na.rm |
logical; whether to omit |
Details
monotonicty
determines the monotonicy (first derivative) of a numeric
vector as one of:
stictly increasing,
increasing / montonically increasing / non-decreasing,
decreasing / monotonically decreasing / non-increasing,
strictly decreasing, or
constant
ordering tests, e.g. is_increasing are more efficient at testing.
monotonicity()
is an alias for ordering
.
Value
integer;
-
2 : stictly increasing
-
1 : increasing / montonically increasing / non-decreasing
-
0 : non-ordered or constant
-
-1: decreasing / monotonically decreasing / non-increasing
-
-2: strictly decreasing
-
NA
:contains only
NAs all
na.rmdid not resolve all
NA's
References
http://en.wikipedia.org/wiki/Monotonic_function http://stackoverflow.com/questions/13093912/how-to-check-if-a-sequence-of-numbers-is-monotonically-increasing-or-decreasing
Examples
ordering( 1:3 ) # 2
ordering( c(1,1,3) ) # 1
ordering( c(1,0,1) ) # 0 "No ordering, does not apply constant"
ordering( c(3,1,1) ) # -1
ordering( 3:1 ) # -2