comparisons: Enhanced comparisons

Description Usage Arguments Author(s) See Also Examples

Description

These operators introduce improved NA handling, reliable floating point tests, and intervals. Specifically:

Equality that handles missing values

Floating point equality, an important bit of functionality missing in base R (%~=%)

Strict (value and type) equality, for those familiar with Javascript ===

Greater/less than or equal to with missing value equality

Greater/less than or equal to with floating point and missing equality

Between (ends excluded)

Between (ends included)

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

a vector

y

a vector

Author(s)

Ben Wiseman, benjamin.wiseman@kornferry.com

See Also

Other comparisons: floating_point_comparisons

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 ## Greater/Less than | Equal

 c(1, NA, 3, 4)  ==  c(1, NA, 4, 3)
 #  TRUE    NA  FALSE FALSE

 c(1, NA, 3, 4) %==% c(1, NA, 4, 3)
 #  TRUE  TRUE  FALSE FALSE

 c(1, NA, 3, 4) %>=% c(1, NA, 4, 3)
 #  TRUE  TRUE FALSE  TRUE

 c(1, NA, 3, 4) %<=% c(1, NA, 4, 3)
 #  TRUE  TRUE TRUE  FALSE


 # Strict equality - a la javascript's ===
 # Only tru if the class and value of x and y are the same
x <- int(2)
y <- 2
x == y         # TRUE
x %===% y      # FALSE
x %===% int(y) # TRUE


 # NOTE parentheses surrounding expression before this operator are necessary
 # Without parentheses it would be interpreted as .1 + .1 + (.1 %~=% .3)


 #### Between ####

 # ends excluded

 2 %><% c(1, 3)
 # TRUE

 3 %><% c(1, 3)
 # FALSE

 # ends included

 2 %>=<% c(1, 3)
 # TRUE

 3 %>=<% c(1, 3)
 # TRUE

roperators documentation built on Feb. 10, 2022, 1:07 a.m.