R/monotonic.R

nondecreasing <- function(x, ...)UseMethod('nondecreasing')
nondecreasing.default <- function(x, strict=FALSE, ...){
  if(strict) y <- x > prev(x)
  else y <- x >= prev(x)
  if(length(y)) y[[1]] <- TRUE
  y
}
nonincreasing <- function(x,...)UseMethod('nonincreasing')
nonincreasing.default <- function(x, strict=FALSE, ...){
  if(strict) y <- x < prev(x)
  else y <- x <= prev(x)
  if(length(y)) y[[1]] <- TRUE
  y
}
monotonic <- function(x, ...)UseMethod('monotonic')
monotonic.default <- function(x, strict=FALSE, ...)all(
	nondecreasing(x,strict=strict,...)) || 
	all(nonincreasing(x,strict=strict,...)
)

Try the metrumrg package in your browser

Any scripts or data that you put into this service are public.

metrumrg documentation built on May 2, 2019, 5:55 p.m.