o zero: First,
the mean absolute difference of the two numerical vectors is computed. If this
is smaller than ` tolerance ` or not finite, absolute differences are used,
otherwise relative differences scaled by the mean absolute ` target ` value.
Note that these comparisons are computed only for those vector elements where
` target ` is not ` [ NA ](/link/NA?package=base&version=3.6.2) ` and differs
from ` current ` . If ` countEQ ` is true, the equal and ` NA ` cases are
_counted_ in determining “sample” size.

If ` scale ` is numeric (and positive), absolute comparisons are made after
scaling (dividing) by ` scale ` .

For complex ` target ` , the modulus ( ` [ Mod
](/link/Mod?package=base&version=3.6.2) ` ) of the difference is used: `
all.equal.numeric ` is called so arguments ` tolerance ` and ` scale ` are
available.

The ` [ list ](/link/list?package=base&version=3.6.2) ` method compares
components of ` target ` and ` current ` recursively, passing all other
arguments, as long as both are “list-like”, i.e., fulfill either ` [ is.vector
](/link/is.vector?package=base&version=3.6.2) ` or ` [ is.list
](/link/is.list?package=base&version=3.6.2) ` .

The ` [ environment ](/link/environment?package=base&version=3.6.2) ` method
works via the ` list ` method, and is also used for reference classes (unless
a specific ` all.equal ` method is defined).

The methods for the date-time classes by default allow a tolerance of `
tolerance = 0.001 ` seconds, and ignore ` scale ` .

` attr.all.equal ` is used for comparing ` [ attributes
](/link/attributes?package=base&version=3.6.2) ` , returning ` NULL ` or a `
character ` vector.

##  References

Chambers, J. M. (1998) _Programming with Data. A Guide to the S Language_ .
Springer (for ` = ` ).

##  See Also

` [ identical ](/link/identical?package=base&version=3.6.2) ` , ` [ isTRUE
](/link/isTRUE?package=base&version=3.6.2) ` , ` [ ==
](/link/%3D%3D?package=base&version=3.6.2) ` , and ` [ all
](/link/all?package=base&version=3.6.2) ` for exact equality testing.

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fall.equal&utm_source=r-docs&utm_medium=docs&utm_term=all.equal&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    all.equal(pi, 355/113)
    # not precise enough (default tol) > relative error
    
    d45 <- pi*(1/4 + 1:10)
    stopifnot(
    all.equal(tan(d45), rep(1, 10)))          # TRUE, but
    all      (tan(d45) == rep(1, 10))         # FALSE, since not exactly
    all.equal(tan(d45), rep(1, 10), tolerance = 0)  # to see difference
    
    ## advanced: equality of environments
    ae <- all.equal(as.environment("package:stats"),
                    asNamespace("stats"))
    stopifnot(is.character(ae), length(ae) > 10,
              ## were incorrectly "considered equal" in R <= 3.1.1
              all.equal(asNamespace("stats"), asNamespace("stats")))
    
    ## A situation where  'countEQ = TRUE' makes sense:
    x1 <- x2 <- (1:100)/10;  x2[2] <- 1.1*x1[2]
    ## 99 out of 100 pairs (x1[i], x2[i]) are equal:
    plot(x1,x2, main = "all.equal.numeric() -- not counting equal parts")
    all.equal(x1,x2) ## "Mean relative difference: 0.1"
    mtext(paste("all.equal(x1,x2) :", all.equal(x1,x2)), line= -2)
    ##' extract the 'Mean relative difference' as number:
    all.eqNum <- function(...) as.numeric(sub(".*:", '', all.equal(...)))
    set.seed(17)
    ## When x2 is jittered, typically all pairs (x1[i],x2[i]) do differ:
    summary(r <- replicate(100, all.eqNum(x1, x2*(1+rnorm(x1)*1e-7))))
    mtext(paste("mean(all.equal(x1, x2*(1 + eps_k))) {100 x} Mean rel.diff.=",
                signif(mean(r), 3)), line = -4, adj=0)
    ## With argument  countEQ=TRUE, get "the same" (w/o need for jittering):
    mtext(paste("all.equal(x1,x2, countEQ=TRUE) :",
              signif(all.eqNum(x1,x2, countEQ=TRUE), 3)), line= -6, col=2)
    # }
    

Run the code above in your