I want to use a character vector containing column names in by
in data.table
along with the interactive way of defining groups. The vector contains columns which are common across a few data.table
s, but each data.table
has a few unique columns. Is that possible? Example below.
library(data.table)
mtcarsdt <- data.table(mtcars)
bycols <- c('cyl', 'gear') # Defined for use across multiple data.tables
mtcarsdt[
, .(mpg = mean(mpg)), # This does not work.
by = c('carb%%2', bycols) # How can I make this work?
]
mtcarsdt[
, .(mpg = mean(mpg)),
by = .(carb%%2, cyl, gear) # This works
]