is_constant {ordering}R Documentation

ordering Tests

Description

Tests vectors for (strictly) increasing, decreasing, monotonic and constant properties

Usage

is_constant(x, na.rm = TRUE)

is_increasing(x, na.rm = TRUE)

is_strictly_increasing(x, na.rm = na.omit)

is_decreasing(x, na.rm = na.omit)

is_strictly_decreasing(x, na.rm = na.omit)

is_incremental(x, step = 1, na.rm = TRUE)

is_uniform(x, step = NULL, na.rm = TRUE)

is_monotonic(x, na.rm = TRUE)

is_strictly_monotonic(x, na.rm = TRUE)

is_sorted(x, na.rm = TRUE)

is_strictly_sorted(x, na.rm = TRUE)

is_unsorted(...)

is_strictly_unsorted(...)

Arguments

x

vector

na.rm

function or NULL; action to perform on input to handle the missing values

step

integer; step size for is_incremental. (Default: 1)'

...

used for passing default arguments

Details

Tests to various monotone properties of vectors.

is_incremental determines if x is incremental, i.e. monotonic and equally spaced.

is_uniform is a wrapper around is_incremental with step=1

is_[strictly_]monotonic determine the sort properties of x.

This differes from base::is.unsorted() which should more properly be called is.increasing since base::is.unsorted(3:1) == TRUE; 3:1 is obviously sorted.

is_sorted() is a alias for is_monotonic() and is_strictly_sorted() is an alias for is_strictly_monotonic().

Value

logical or NA. (NB: NA is returned because it is a logical vector and this is needed to put these results cleanly in tables.)

logical

Note

The behavior of this package is The functions base::is.unsorted() is perhaps misnamed and should properly be names is_not_increasing since base::is.unsorted(3:1) == TRUE after all vector 3,2,1 is sorted but not increasing.

See Also

Examples

  
  is_constant( rep(3,5) )

  is_increasing( 1:5 )                   # TRUE
  is_increasing( c(1,2,1,3) )            # FALSE
  
  is_increasing( c(1,NA,2,3) )           # NA 
  is_increasing( c(1,NA,2,3), na.omit )  # TRUE

  is_monotonic( 1:5 )                    # TRUE
  is_monotonic( -5:5 )                   # TRUE
  is_monotonic( 5:-5 )                   # TRUE
  is_monotonic( c(1,5,3))                # FALSE
  

  is_incremental(1:5 )
  is_incremental( c(1,2,5))
  
  is_incremental(1:5, step=NULL)
  is_uniform(1:5)


  is_monotonic( 1:3 )
  is_strictly_monotonic(1:3)
  
  is_monotonic( c(1,3,2) )
  is_strictly_monotonic( c(1,3,2) )
  
  is_sorted(1:3)
  is_sorted(c(1,3,2))   
  
  lets <- letters[1:3]
  is_monotonic( lets )
  is_monotonic( c('a', 'c', 'b') )
  
  is_sorted(1:10)
  
  is_sorted(-5:5)
  is_sorted(5:-5)
  
  is_sorted( letters )
  is_sorted( rev(letters) )
  

[Package ordering version 0.7.0 Index]