Message-ID: <95637f81-525d-2538-f9e9-ed1920a41f5c@ieu.uzh.ch>
Date: 2019-02-21T14:10:04Z
From: Pascal A. Niklaus
Subject: data.table: reference column in "i"-part by column name in string object
I am converting data.frame-based code to data.table, for performance
reasons.
Is there a way to refer to columns using expressions in the "i"-part?
Here is an example:
a <- data.table(x=rep(LETTERS[1:10],each=2), y=1:20)
v <- "x"
For the j-part, I can access the column whose name is stored in v as
a[,..v]
However, for the i-part I did not find a good way to achieve the same.
For a simple case, the following works
xx <- "B"
a[xx, on=v]
However, I can't see how this is easily expanded to more complex logical
expressions.
Pascal