How can I create an infix

后端 未结 3 1555
耶瑟儿~
耶瑟儿~ 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:04

    You can define infix operators as functions:

    `%between%`<-function(x,rng) x>rng[1] & x

    As pointed out by @flodel, this operator is vectorized:

    1:5 %between% c(1.5,3.5)
    # [1] FALSE  TRUE  TRUE FALSE FALSE
    

提交回复
热议问题