[datatable-help] Column Name Masking Variable
Bernstein, Elliot J
EJBernstein at wellington.com
Tue Nov 28 18:50:26 CET 2017
I'm running into an issue where a data.table has a column with the same name as a variable, and I would like to reference the variable in an i expression.
For example,
library(data.table)
x <- data.table(y = 1:10, z = 11:20)
setkey(x, y)
z <- data.table(y = 1:5, w = 21:25)
setkey(z, y)
I want to extract the subset of x with values of y that are not in the y column of the data.table z. I can do the following:
ind <- setdiff(x[,y], z[,y])
x[ind]
But I can't do the following:
x[setdiff(y, z[,y])]
because it tries to use the column z instead of the data.table z. Is there any way to get around that? I tried using "with = FALSE", but that only seems to apply to the j expression.
Thank you for your help.
- Elliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20171128/3a5eeaf2/attachment.html>
More information about the datatable-help
mailing list