Subset data.table by logical column
I have a data.table with a logical column. Why the name of the logical column can not be used directly for the i argument? See the example. dt <- data.table(x = c(T, T, F, T), y = 1:4) # Works dt[dt$x] dt[!dt$x] # Works dt[x == T] dt[x == F] # Does not work dt[x] dt[!x] mnel From ?data.table Advanced: When i is a single variable name, it is not considered an expression of column names and is instead evaluated in calling scope. So dt[x] will try to evaluate x in the calling scope (in this case the global environment) You can get around this by using ( or { or force dt[(x)] dt[{x}] dt[force(x)]