rd_equal {intervals} | R Documentation |
Algorithms in this package need to be able to accurately determine when interval endpoints coincide. If floating point values are used for endpoints, required exact equality is not appropriate, so relative difference is used instead.
rd_equal(x, y, tolerance = .Machine$double.eps^0.5)
x |
A vector of values to be compared, point-wise, to y . |
y |
A vector fo values of the same length as x . |
tolerance |
Tolerance for establishing approximate equality. The default value
is the same one used by all.equal.numeric ,
|
For each component in x
and its partner in y
, the
absolute value of difference is compared to the larger of the two
individual absolute values. The values are deemed to be equal if the
ratio is less than tolerance
. When one or both values are
infinite, a simple comparison with ==
is made; when one or both
are NA
, a NA
is returned.
A logical vector of the same length as x
and y
.
See all.equal.numeric
for related, though distinct,
functionality. Specifically, the comparisons made by
all.equal.numeric
are relative to the mean
absolute value of the target; rd_equal
, on the other hand,
makes pointwise relative difference comparisons.
eps <- 1e-5 x <- 1:2 y <- x + c( eps, 0 ) intervals:::rd_equal(x, y) # The relative difference for all.equal() uses the average across the # target vector in the denominator, while rd_equal() computes the # denominator coordinate-wise: intervals:::rd_equal(x, y, tolerance = eps) all.equal(x, y, tolerance = eps) # Handling non-finite values intervals:::rd_equal( c( .8, .9, NA, Inf, -Inf ), c( 1, 1, 1, Inf, Inf ), tol = .1 )