A) Instead of this (where cars <- data.table(cars))
cars[ , .(`Totals:`=.N), by=speed]
I need this
strCo
Edit:
Based on your clarifications, here is an approach with setNames and get. The trick here is that .. instructs the evaluation to occur in the calling environment.
library(data.table)
cars <- data.table(cars)
strFactor <- "dist"
strNewVariable <- "Totals x Factor: "
strBy <- "speed"
cars[ get(strFactor) > 50,
setNames(.(.N * get(..strFactor)),strNewVariable),
by=strBy]