How can I create an infix

后端 未结 3 1557
耶瑟儿~
耶瑟儿~ 2020-12-09 17:01

I would like to have an infix operator %between% in R -- to check to see if x is between lower bound l and upper bound

3条回答
  •  难免孤独
    2020-12-09 17:14

    This function exists in the package data.table (with the slight difference that the bounds are included), implemented as:

    between <- function(x,lower,upper,incbounds=TRUE)
    {
      if(incbounds) x>=lower & x<=upper
      else x>lower & x

    It can be used as between(x,lower,upper) or x %between% c(lower, upper)

提交回复
热议问题