I want to select rows in a data.table based on a variable set elsewhere and I am missing some key point of syntax.
library(data.table)
DT = data.table(x=rep(c("a","b","c"),each=3), y=c(1,3,6), v=1:9)
DT
#this works as expected and does what I want
DT[y<3 & v >3]
#but how do I pass my selection criteria in?
a1<-"y<3 & v>3"
a2<-quote(y<3 & v>3)
#so that one of these works?
DT[a1] #error
DT[a2] #error
DT[eval(a1)] #error