I am using data.table and I want to filter a data.table within a function where I am passing the name of the column as a character vector.
For a simple reproducible example let's take the mtcars dataset of base R.
I can write using data.table syntax:
mtcars[am == 1, .N ]
But what if the name of the variable of interest -- i.e. am -- is stored as a character vector, i.e. "am"?
Your advice will be appreciated.
DT = data.table(mtcars); vname = "am"; DT[.(1), on=vname, .N]is what I'd do. - Frank