Column Name Masking Variable

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Column Name Masking Variable

Bernstein, Elliot J

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,




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



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

datatable-help mailing list
[hidden email]