ineq: Less than or Less than and equal operators that can be...

Description Usage Arguments Details Value Note Author(s) Examples

Description

Comparison operators that can be chained together into something like 0 %<% x %<% 1 instead of 0 < x \&\& x < 1.

Usage

1
2
x %<% y
x %<=% y

Arguments

x,y

Values to compare

Details

These functions/operators allow chained inequalities. To specify that you want the values between two values (say 0 and 1) you can use 0 %<% x %<% 1 rather than 0 < x \&\& x < 1 .

Value

A logical vector is returned that can be used for subsetting like <, but the original values are included as attributes to be used in additional comparisons.

Note

This operator is not fully associative and has different precedence than < and <=, so be careful with parentheses. See the examples.

Author(s)

Greg Snow, 538280@gmail.com

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
x <- -3:3

 -2 %<% x %<% 2
c( -2 %<% x %<% 2 )
x[ -2 %<% x %<% 2 ]
x[ -2 %<=% x %<=% 2 ]


x <- rnorm(100)
y <- rnorm(100)

x[ -1 %<% x %<% 1 ]
range( x[ -1 %<% x %<% 1 ] )


cbind(x,y)[ -1 %<% x %<% y %<% 1, ]
cbind(x,y)[ (-1 %<% x) %<% (y %<% 1), ]
cbind(x,y)[ ((-1 %<% x) %<% y) %<% 1, ]
cbind(x,y)[ -1 %<% (x %<% (y %<% 1)), ]
cbind(x,y)[ -1 %<% (x %<% y) %<% 1, ] # oops


3 
3 

TeachingDemos documentation built on April 14, 2020, 6:26 p.m.