This answer came from Arun. All the credit goes to Arun
library(data.table)
DT <- data.table(x = rep(c("a", "b", "c"), each=2000), y=c(rep(c(1,3,6), each = 1)) , key = c("x", "y"))
DT["b"][!J(unique(x), 1)]
This subsets the data based on a match for all rows containing b
in column x
and no match to 1
in all the rows of column y
.