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

Pfister, R., Tonn, S., Schaaf, M., Wirth, R. (2024). mousetRajectory: Mouse tracking analyses for behavioral scientists. The Quantitative Methods for Psychology, 20(3), 217-229. doi:10.20982/tqmp.20.3.p217

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