3

While all.equal is a very powerful tool, with a cornucopia of informative response strings, I wanted an equivalent function which simply returned TRUE/FALSE for near-equality. (I'm aware of the standard tricks like identical(all.equal(foo,bar), TRUE) ). I wrote the following code snippet, but was wondering if I'd overlooked a similar function in one of the R packages.

approxeq <- function(x,y,tolerance = .Machine$double.eps ^ 0.5,...) {
   #Note: better input validation should be written
   if (length(x) != length(y)) stop('lengths must be equal')
   checkit <- abs(x-y) < tolerance
    return(invisible(checkit))
}

The main difference between approxeq and all.equal is that the former gives me element-by-element equality test results. I'm not saying this is better, just different. So, does anyone know if there is a similar (and presumably more robust) function in a released package?

4

0 回答 0