equal: Testing whether all elements in a vector are equal.

Description Usage Arguments Value Examples

Description

Tests whether all the elements in a numeric vector are equal. A special care is needed with such operations because we might be working with real numbers and this requires stating some threshold for declaring elements to be the same. If any of the elements are NA, the function will not work and the result will be an error. See also http://stackoverflow.com/questions/4752275/test-for-equality-among-all-elements-of-a-single-vector

Usage

1
equal(x, tol = 1e-16)

Arguments

x

A numeric vector.

tol

A scalar, small value, required to test the equality of real numbers.

Value

A logical value, TRUE, FALSE or NA.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# create some vectors
x <- c(1,2,3)
y <- c(1,NA,1)
z <- c(1,1,1)
w <- c(1,1,1.01)

# these produce logical values
equal(x)
equal(z)
equal(w, 0.1)

# running this will produce an error
# equal(y)

hstojic/hfunk documentation built on May 17, 2019, 6:16 p.m.