%<% {TeachingDemos} | R Documentation |
Comparison operators that can be chained together into something like 0 %<% x %<% 1 instead of 0 < x \&\& x < 1.
x %<% y x %<=% y
x,y |
Values to compare |
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
.
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.
This operator is not fully associative, so be careful with parentheses. See the examples.
Greg Snow, greg.snow@imail.org
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