R语言R for data science

data.table中 between 与 inrange的区别

2019-04-27  本文已影响3人  热衷组培的二货潜

问题来源于一片博客data.table 与 dplyr 的区别

查阅到 between vs inrange in data.table

between(x, lower, upper, incbounds=TRUE)
x %between% y
inrange(x, lower, upper, incbounds=TRUE)
x %inrange% y
> library(data.table)
> X = data.table(a=1:5, b=6:10, c=c(5:1))
> X
   a  b c
1: 1  6 5
2: 2  7 4
3: 3  8 3
4: 4  9 2
5: 5 10 1

> X[a %between% list(c, b)]
   a  b c
1: 3  8 3
2: 4  9 2
3: 5 10 1

> X[a %between% list(b, c)]
Empty data.table (0 rows) of 3 cols: a,b,c

> X[a %inrange% list(c, b)]
   a  b c
1: 1  6 5
2: 2  7 4
3: 3  8 3
4: 4  9 2
5: 5 10 1

> X[a %inrange% list(b, c)]
Empty data.table (0 rows) of 3 cols: a,b,c
上一篇下一篇

猜你喜欢

热点阅读