[R] data.table: reference column in "i"-part by column name in string object

Pascal A. Niklaus p@@c@|@n|k|@u@ @end|ng |rom |eu@uzh@ch
Thu Feb 21 23:09:31 CET 2019

On 21.02.19 20:43, Rui Barradas wrote:
> Hello,
> I don't understand the question.
> Like this?
> xx <- "B"
> yy <- "D"
> a[xx, on = v]
> a[c(xx, yy), on = v]
> Note that .(xx, yy) doesn't work. It outputs something else.
> Could you give an example of more complicated expressions you have 
> doubts with?

Let's assume I'd like to create a subset like this, in data.frame syntax:

d[ (d[[v]] == a | d$b == "c") & d$c>2, ]

Here I have a column referenced by its name (stored in v), and compared 
to a value stored in a, and the whole thing is part of a more complex 
logical expression. I could write it in this conventional way, but I 
wondered whether there is a better way that would leverage some of 
data.tables syntax.


More information about the R-help mailing list