Let's first create a simple data.table in r.
dt=data.table(x1=1:5,
x2=11:21)
If we want to subset the data.table with conditions for rows, we can simple do, for example
dt[x1==1]
Now my question is: what if the column name is a variable ? I tried with :
var="x1"
dt[eval(var)==1,]
But this code doesn't work.
eval
works with the following example: if we want to get the some columns by name (that is a variable).
dt[x1==1,eval(var),with=F]