Skip to contents

Checks if a numeric_vector is monotonically in-/decreasing. In particular, it always a good idea to check the time stamps of trajectory data and verify that the logging worked properly.

Usage

is_monotonic(numeric_vector, decreasing = FALSE, strict = TRUE, warn = TRUE)

Arguments

numeric_vector

Number sequence to-be checked.

decreasing

Should the numeric_vector be increasing or decreasing? Defaults to FALSE.

strict

Must the values in-/decrease strictly? Defaults to TRUE, indicating that a strict, not a weak definition of monotony is applied.

warn

Will a warning be issued if the numeric_vector is not monotonic? Defaults to TRUE.

Value

A length-one logical, indicating whether the vector is monotonic.

Details

All objects of length 0 or 1 are monotonic. Data with missing values will not pass the check.

References

Wirth, R., Foerster, A., Kunde, W., & Pfister, R. (2020). Design choices: Empirical recommendations for designing two-dimensional finger tracking experiments. Behavior Research Methods, 52, 2394 - 2416. doi:10.3758/s13428-020-01409-0

Examples


is_monotonic(c(1, 2, 3, 4), warn = FALSE)
#> [1] TRUE
is_monotonic(c(1, 2, 2, 3), warn = FALSE)
#> [1] FALSE
is_monotonic(c(1, 2, 2, 3), strict = FALSE, warn = FALSE)
#> [1] TRUE
is_monotonic(c(4, 0, -1, -1, -5),
  decreasing = TRUE,
  strict = FALSE, warn = FALSE
)
#> [1] TRUE