# [R] Operator proposal: %between%

Gabor Grothendieck ggrothendieck at gmail.com
Fri Sep 5 10:36:57 CEST 2014

```On Thu, Sep 4, 2014 at 10:41 AM, Torbjørn Lindahl
<torbjorn.lindahl at gmail.com> wrote:
> Not sure if this is the proper list to propose changes like this, if it
> passes constructive criticism, it would like to have a %between% operator
> in the R language.
>

There is a between function in the data.table package.

> library(data.table)
> between
function (x, lower, upper, incbounds = TRUE)
{
if (incbounds)
x >= lower & x <= upper
else x > lower & x < upper
}

and also in the tis package which works differently:

> library(tis)
> between
function (y, x1, x2)
{
y <- unclass(y)
x1 <- unclass(x1)
x2 <- unclass(x2)
small <- pmin(x1, x2)
large <- pmax(x1, x2)
(y >= small) & (y <= large)
}

In addition, SQL has a between operator

> library(sqldf)
> sqldf("select * from BOD where Time between 3 and 5")
Time demand
1    3   19.0
2    4   16.0
3    5   15.6

```
{"ft_lang_label":"__label__en","ft_lang_prob":0.8181452,"math_prob":0.94424456,"size":997,"snap":"2020-45-2020-50","text_gpt3_token_len":330,"char_repetition_ratio":0.10171198,"word_repetition_ratio":0.0,"special_character_ratio":0.33801404,"punctuation_ratio":0.14285715,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97857404,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-10-20T18:45:13Z\",\"WARC-Record-ID\":\"<urn:uuid:11305367-e9ad-4797-8eb4-1b97e84a7983>\",\"Content-Length\":\"3862\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:79e1fefb-d528-4ca6-8037-a9029a89ad0e>\",\"WARC-Concurrent-To\":\"<urn:uuid:9641020b-8d66-4b73-9dfb-6d9a4260bd25>\",\"WARC-IP-Address\":\"129.132.119.195\",\"WARC-Target-URI\":\"https://www.stat.math.ethz.ch/pipermail/r-help/2014-September/421458.html\",\"WARC-Payload-Digest\":\"sha1:OTZ2KVLMQVK5MCHNZSETENCURQI7WWJO\",\"WARC-Block-Digest\":\"sha1:ATN2GXCH36AFRJQSBQRDTVVNHP4ODMYA\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-45/CC-MAIN-2020-45_segments_1603107874026.22_warc_CC-MAIN-20201020162922-20201020192922-00218.warc.gz\"}"}