Skip to contents

Returns TRUE if all elements in a vector are the same.

Usage

is_rep(x, tol = NULL)

Arguments

x

A vector.

tol

A numeric value for the tolerance factor when comparing numerics. A good value might be .Machine$double.eps ^ 0.5. If not NULL, it assumes that x is a numeric and NA values should be removed.

Value

TRUE or FALSE

Details

Uses length(unique(x)) == 1 by default. Uses abs(max(x, na.rm = TRUE) - min(x, na.rm = TRUE)) < tol as a faster method for numeric cases when tol is set.

Examples

#----------------------------------------------------------------------------
# is_rep() examples
#----------------------------------------------------------------------------
library(bkmisc)

x <- c("a", "b")
y <- c("a", "a")
is_rep(x)
#> [1] FALSE
is_rep(y)
#> [1] TRUE

x <- 1:2
is_rep(x)
#> [1] FALSE
is_rep(x, tol = .Machine$double.eps ^ 0.5)
#> [1] FALSE

x <- c(1, 1, NA)
is_rep(x)
#> [1] FALSE
is_rep(x, tol = .Machine$double.eps ^ 0.5)
#> [1] TRUE