all_equal | R Documentation |
A memory-efficient alternative to all.equal.numeric()
.
all_equal(
x,
y,
tol = getOption("cppdoubles.tolerance", sqrt(.Machine$double.eps)),
na.rm = FALSE
)
x |
A double vector. |
y |
A double vector. |
tol |
A double vector of tolerances. |
na.rm |
Should |
all_equal
compares each pair of
double-precision floating point numbers
in the same way as double_equal
.
If any numbers differ, the algorithm breaks immediately,
which can offer significant speed when there are differences at
the start of a vector.
All arguments are recycled except na.rm
.
A logical vector of length 1.
The result should match all(double_equal(x, y))
, including the way
NA
values are handled.
library(cppdoubles)
library(bench)
x <- seq(0, 1, 0.2)
y <- sqrt(x)^2
all_equal(x, y)
# Comparison to all.equal
z <- runif(10^4, 1, 100)
ones <- rep(1, length(z))
mark(base = isTRUE(all.equal(z, z)),
cppdoubles = all_equal(z, z),
iterations = 100)
mark(base = isTRUE(all.equal(z, ones)),
cppdoubles = all_equal(z, ones),
iterations = 100)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.