Just wondering if there is a slicker way to subset a data.table. Basically I have a big table with millionish rows and hundreds cols. I want to subset it based on an integer col/s having a value between a range defined by me.
I was wondering if the set the relevant column as the Key it would be binary search but then not sure if I can find the rows between a range of values.
Contrived example below.
> n = 1e7
> dt <- data.table(a=rnorm(n),b=sample(letters,replace=T,n))
> system.time(subset(dt, a > 1 & a < 2))
user system elapsed
1.596 0.000 1.596
> system.time(dt[a %between% c(1,2)])
user system elapsed
1.168 0.000 1.168
can something like this be done?
setkey(dt,a)
dt[ ] : get me the rows between 1 and 2 values of the key
Thanks! -Abhi