EVOLUTION-MANAGER
Edit File: between.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Convenience functions for range subsets.</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for between {data.table}"><tr><td>between {data.table}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2> Convenience functions for range subsets. </h2> <h3>Description</h3> <p>Intended for use in <code>i</code> in <code>[.data.table</code>. </p> <p><code>between</code> is equivalent to <code>lower<=x & x<=upper</code> when <code>incbounds=TRUE</code>, or <code>lower<x & y<upper</code> when <code>FALSE</code>. With a caveat that <code>NA</code> in <code>lower</code> or <code>upper</code> are taken as unlimited bounds not <code>NA</code>. This can be changed by setting <code>NAbounds</code> to <code>NA</code>. </p> <p><code>inrange</code> checks whether each value in <code>x</code> is in between any of the intervals provided in <code>lower,upper</code>. </p> <h3>Usage</h3> <pre> between(x, lower, upper, incbounds=TRUE, NAbounds=TRUE, check=FALSE) x %between% y inrange(x, lower, upper, incbounds=TRUE) x %inrange% y </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p> Any orderable vector, i.e., those with relevant methods for <code>`<=`</code>, such as <code>numeric</code>, <code>character</code>, <code>Date</code>, etc. in case of <code>between</code> and a numeric vector in case of <code>inrange</code>.</p> </td></tr> <tr valign="top"><td><code>lower</code></td> <td> <p> Lower range bound. Either length 1 or same length as <code>x</code>.</p> </td></tr> <tr valign="top"><td><code>upper</code></td> <td> <p> Upper range bound. Either length 1 or same length as <code>x</code>.</p> </td></tr> <tr valign="top"><td><code>y</code></td> <td> <p> A length-2 <code>vector</code> or <code>list</code>, with <code>y[[1]]</code> interpreted as <code>lower</code> and <code>y[[2]]</code> as <code>upper</code>.</p> </td></tr> <tr valign="top"><td><code>incbounds</code></td> <td> <p><code>TRUE</code> means inclusive bounds, i.e., [lower,upper]. <code>FALSE</code> means exclusive bounds, i.e., (lower,upper). It is set to <code>TRUE</code> by default for infix notations.</p> </td></tr> <tr valign="top"><td><code>NAbounds</code></td> <td> <p> If <code>lower</code> (<code>upper</code>) contains an <code>NA</code> what should <code>lower<=x</code> (<code>x<=upper</code>) return? By default <code>TRUE</code> so that a missing bound is interpreted as unlimited. </p> </td></tr> <tr valign="top"><td><code>check</code></td> <td> <p> Produce error if <code>any(lower>upper)</code>? <code>FALSE</code> by default for efficiency, in particular type <code>character</code>. </p> </td></tr> </table> <h3>Details</h3> <p><em>non-equi</em> joins were implemented in <code>v1.9.8</code>. They extend binary search based joins in <code>data.table</code> to other binary operators including <code>>=, <=, >, <</code>. <code>inrange</code> makes use of this new functionality and performs a range join. </p> <h3>Value</h3> <p>Logical vector the same length as <code>x</code> with value <code>TRUE</code> for those that lie within the specified range. </p> <h3>Note</h3> <p> Current implementation does not make use of ordered keys for <code>%between%</code>. </p> <h3>See Also</h3> <p><code><a href="data.table.html">data.table</a></code>, <code><a href="like.html">like</a></code>, <code><a href="chmatch.html">%chin%</a></code> </p> <h3>Examples</h3> <pre> 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 </pre> <hr /><div style="text-align: center;">[Package <em>data.table</em> version 1.14.4 <a href="00Index.html">Index</a>]</div> </body></html>