relational-operators: Relational operators with tolerance

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Binary operators which allow the comparison of values in numeric vectors.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
x %>=% y

x %>>% y

x %<=% y

x %<<% y

x %==% y

x %!=% y

Arguments

x

Any numeric object.

y

Any numeric object.

Details

These are similar to their counterparts in base, except a tolerance fpCompare.tolerance can be specified via options to account for floating point rounding errors:

fpCompare base
---------------- -----------
%>=% >=
%>>% >
%<=% <=
%<<% <
%==% ==
%!=% !=

Inspired by R FAQ 7.31 (http://ow.ly/LiU7K) and this post (http://stackoverflow.com/a/2769618/1380598).

Value

A logical vector indicating the result of the element by element comparison. The elements of shorter vectors are recycled as necessary.

Author(s)

Alex Chubaty

See Also

all.equal, .Machine

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
x1 <- 0.5 - 0.3
x2 <- 0.3 - 0.1
x1 == x2                           # FALSE on most machines
x1 %==% x2                         # TRUE everywhere
identical(all.equal(x1, x2), TRUE) # TRUE everywhere

set.seed(123)
a <- 1:6
b <- jitter(1:6, 1e-7)
print(rbind(a, b), digits = 16)

b %<=% a
b %<<% a
b %>=% a
b %>>% a
b %==% a
b %!=% a

fpCompare documentation built on June 12, 2018, 5:04 p.m.