data.table in R - multiple filters using multiple keys - binary search -
i don't understand how can filter based on multiple keys in data.table . take built-in mtcars dataset. dt <- data.table(mtcars) setkey(dt, am, gear, carb) following vignette , know if want have filtering corresponds am == 1 & gear == 4 & carb == 4 , can say > dt[.(1, 4, 4)] mpg cyl disp hp drat wt qsec vs gear carb 1: 21 6 160 110 3.9 2.620 16.46 0 1 4 4 2: 21 6 160 110 3.9 2.875 17.02 0 1 4 4 and gives correct result. furthermore, if want have am == 1 & gear == 4 & (carb == 4 | carb == 2) , works > dt[.(1, 4, c(4, 2))] mpg cyl disp hp drat wt qsec vs gear carb 1: 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 2: 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 3: 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 4: 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2 however, when want have am == 1 & (gear == 3 | gear == 4) & (carb == 4 | carb == 2) , plausible > dt[.(1, c(3