Subset data.table by logical column

后端 未结 3 2196
猫巷女王i
猫巷女王i 2020-12-03 09:51

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.

3条回答
  •  既然无缘
    2020-12-03 10:38

    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)]
    

提交回复
热议问题