diff --git a/R/between.R b/R/between.R index a56b25d87..e166c2527 100644 --- a/R/between.R +++ b/R/between.R @@ -1,9 +1,9 @@ -between <- function(x,lower,upper,incbounds=TRUE) -{ +between <- function(x,lower,upper,incbounds=TRUE) { if(incbounds) x>=lower & x<=upper else x>lower & x=`, `>`, `<=`, `<` and `==`. For e.g., `X[Y, on=.(a, b>b)]` looks for `X.a == Y.a` first and within those matching rows for rows where`X.b > Y.b`. Partly addreses [#1452](https://github.com/Rdatatable/data.table/issues/1452). + 33. `%between%` is vectorised which means we can now do: `DT[x %between% list(y,z)]` which is equivalent to `DT[x >= y & x <= z]`, [#534](https://github.com/Rdatatable/data.table/issues/534). Thanks @MicheleCarriero for filing the issue and the idea. + #### BUG FIXES 1. Now compiles and runs on IBM AIX gcc. Thanks to Vinh Nguyen for investigation and testing, [#1351](https://github.com/Rdatatable/data.table/issues/1351). diff --git a/man/between.Rd b/man/between.Rd index 384a7830e..0216eaafc 100644 --- a/man/between.Rd +++ b/man/between.Rd @@ -3,7 +3,7 @@ \alias{\%between\%} \title{ Convenience function for range subset logic. } \description{ - Intended for use in \code{i} in \code{[.data.table}. + Intended for use in \code{i} in \code{[.data.table}. From \code{v1.9.8}, \code{between} is vectorised. } \usage{ between(x,lower,upper,incbounds=TRUE) @@ -11,9 +11,9 @@ x \%between\% y } \arguments{ \item{x}{ Any orderable vector, i.e., those with relevant methods for \code{`<=`}, such as \code{numeric}, \code{character}, \code{Date}, ... } - \item{lower}{ Lower range bound. } - \item{upper}{ Upper range bound. } - \item{y}{ A length-2 vector, with \code{y[1]} interpreted as \code{lower} and \code{y[2]} as \code{upper}. } + \item{lower}{ Lower range bound. Usually of length=\code{1} or \code{length(x)}.} + \item{upper}{ Upper range bound. Usually of same length as \code{lower}.} + \item{y}{ A length-2 \code{vector} or \code{list}, with \code{y[[1]]} interpreted as \code{lower} and \code{y[[2]]} as \code{upper}.} \item{incbounds}{ \code{TRUE} means inclusive bounds, i.e., [lower,upper]. \code{FALSE} means exclusive bounds, i.e., (lower,upper). } } % \details{ @@ -24,7 +24,9 @@ x \%between\% y \note{ Current implementation does not make use of ordered keys. \code{incbounds} is set to \code{TRUE} for the infix notation \code{\%between\%}. } \seealso{ \code{\link{data.table}}, \code{\link{like}} } \examples{ -DT = data.table(a=1:5, b=6:10) -DT[b \%between\% c(7,9)] +DT = data.table(x=1:5, y=6:10, z=c(5:1)) +DT[y \%between\% c(7,9)] +# NEW feature in v1.9.8, vectorised between +DT[z \%between\% list(x,y)] } \keyword{ data }