approxeq {cgwtools}R Documentation

Do "fuzzy" equality and return a logical vector.

Description

This function compares two vectors (or arrays) of values and returns the near-equality status of corresponding elements. As with all.equal() , the intent is primarily to get around machine limits of representation of floating-point numbers. For integer comparison, just use the base == operator.

Usage

approxeq(x, y, tolerance = .Machine$double.eps^0.5, ...)

Arguments

x, y

The two input items, typically vectors or arrays of data.

tolerance

Set the precision to which abs(x[j] - y[j]) will be compared. The default argument provided is the R-standard value for floats.

...

Not used at this time.

Details

If x and y are of different lengths, the shorter one is recycled and a warning issued.

Value

A vector of the same length as the longer of x or y, consisting of TRUE and FALSE elements, depending on whether the corresponding elements of x and y are within the approximate equality precision desired.

Author(s)

Carl Witthoft, carl@witthoft.com

See Also

all.equal, Comparison, identical

Examples

x<-1:10
y<-x+runif(10)*1e-6
approxeq(x,y) #all FALSE
approxeq(x,y,tolerance=1e-5) #mostly TRUE, probably

[Package cgwtools version 4.1 Index]