Right off the bat, I'm not referring to this question. That question deals with an update by reference kind of scenario. However, if I have still missed a question, I am sorry, please close this question.
Here is what I am talking about.
library(data.table)
x <- setDT(copy(mtcars))
# This is possible
x[, .(mpg = mean(mpg)), keyby = cyl]
colName <- 'mpg'
# How to achieve something like this?
x[, .((colName) = mean(mpg)), keyby = cyl]
Is there some way to make (colName)
work in this case? To be clear, I do not want to update x
, but want to assign the column name directly to the newly created data.table
.