%<% {TeachingDemos}R Documentation

Less than or Less than and equal operators that can be chained together.

Description

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

Usage

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, so be careful with parentheses. See the examples.

Author(s)

Greg Snow, greg.snow@imail.org

Examples


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



[Package TeachingDemos version 2.7 Index]