Skip to contents

Returns TRUE if x is a one-dimensional atomic vector where every element is equal to the first element. Zero-length and length-one vectors are constant.

Usage

is_const(x)

Arguments

x

(atomic vector)
The vector to be tested.

Value

Scalar logical.

Details

NA and NaN are treated as values rather than unknown comparison results. This means c(NA, NA) and c(NaN, NaN) are constant, while c(NA, NaN) and c(1, NA) are not constant.

Non-atomic objects and objects with dimensions return FALSE.

Examples

#----------------------------------------------------------------------------
# is_const() examples
#----------------------------------------------------------------------------
library(bkbase)

is_const(c(1, 1, 1))
#> [1] TRUE
is_const(c(1, 2, 1))
#> [1] FALSE

is_const(c(NA, NA))
#> [1] TRUE
is_const(c(NaN, NaN))
#> [1] TRUE
is_const(c(NA, NaN))
#> [1] FALSE

is_const(integer(0))
#> [1] TRUE
is_const(NULL)
#> [1] FALSE

is_const(matrix(1, nrow = 1))
#> [1] FALSE
is_const(list(1, 1))
#> [1] FALSE