根据data.table
1.8.8 版%between%
,定义如下:
> `%between%`
function (x, y)
between(x, y[1], y[2], incbounds = TRUE)
<bytecode: 0x0000000050912810>
<environment: namespace:data.table>
我认为,通过这个微小的变化,这个函数将被矢量化,
function (x, y)
between(x, y[[1]], y[[2]], incbounds = TRUE)
喜欢between
s <- c(2, 5)
d <- c(7, 9)
> between(3, s, d)
[1] TRUE FALSE
这个想法来自有一个包含两个向量的列表,这向我建议了这种可能的用法:
`between2%` <- function(x, lst) between(x, lst[[1]], lst[[2]], incbounds = TRUE)
> 3%between%c(s,d)
[1] TRUE
> 3%between2%list(s,d)
[1] TRUE FALSE
我的问题是:如果我更换了包中%between%
的任何功能会受到影响吗?data.table
我认为它不应该,[[
应该像原子向量一样[
使用。我对么?谢谢
> 3%between2%c(1,5)
[1] TRUE