
Last chance! 50% off unlimited learning
Sale ends in
i
in [.data.table
.between
is equivalent to x >= lower & x <= upper<="" code=""> when
incbounds=TRUE
, or x > lower & y < upper
when FALSE
.
inrange
checks whether each value in x
is in between any of
the intervals provided in lower,upper
.
between(x, lower, upper, incbounds=TRUE)
x %between% y
inrange(x, lower, upper, incbounds=TRUE)
x %inrange% y
`<=`< code="">, such as numeric
, character
, Date
, etc. in
case of between
and a numeric vector in case of inrange
.
vector
or list
, with y[[1]]
interpreted as lower
and y[[2]]
as upper
.TRUE
means inclusive bounds, i.e., [lower,upper].
FALSE
means exclusive bounds, i.e., (lower,upper). It is set to TRUE
by default for infix notations.
x
with value TRUE
for those
that lie within the specified range.
From v1.9.8+
, between
is vectorised. lower
and
upper
are recycled to length(x)
if necessary.
non-equi joins were recently implemented in v1.9.8
. It extends
binary search based joins in data.table
to other binary operators
including >=, <=,>, <
. inrange
makes use of this new
functionality and performs a range join.
data.table
, like
, %chin%
X = data.table(a=1:5, b=6:10, c=c(5:1))
X[b %between% c(7,9)]
X[between(b, 7, 9)] # same as above
# NEW feature in v1.9.8, vectorised between
X[c %between% list(a,b)]
X[between(c, a, b)] # same as above
X[between(c, a, b, incbounds=FALSE)] # open interval
# inrange()
Y = data.table(a=c(8,3,10,7,-10), val=runif(5))
range = data.table(start = 1:5, end = 6:10)
Y[a %inrange% range]
Y[inrange(a, range$start, range$end)] # same as above
Y[inrange(a, range$start, range$end, incbounds=FALSE)] # open interval
Run the code above in your browser using DataLab