Skip to contents

Are all the elements of a numeric vector (approximately) equal?

Usage

are_all_equal(x, na.rm = FALSE)

Arguments

x

A numeric vector.

na.rm

Remove missing values (FALSE by default; NAs in x will return NA).

Value

Logical, whether all elements of a numeric vector are equal.

Examples

are_all_equal(c(5,5,5))
#> [1] TRUE
are_all_equal(c(5,5,5,6))
#> [1] FALSE
are_all_equal(c(5,5,5,NA,6))
#> [1] NA
are_all_equal(c(5,5,5,NA,6), na.rm=TRUE)
#> [1] FALSE
5==5.000000001
#> [1] FALSE
identical(5, 5.000000001)
#> [1] FALSE
are_all_equal(c(5L, 5, 5.000000001))
#> [1] TRUE