How do I select rows by two criteria in data.table in R
问题 Let's say I have a data.table and I want to select all the rows where the variable x has a value of b. That is easy library(data.table) DT <- data.table(x=rep(c("a","b","c"),each=3), y=c(1,3,6), v=1:9) setkey(DT,x) # set a 1-column key DT["b"] By the way, it appears that one has to set a key, if the key is not set to x then this does not work. By the way what would happen if I set two columns as keys? Anyway, moving along, lets say that I want to select all the rows where the variable x was a