Say I want to create a function that calculates a summary dataset from a data.table in R, and I want to be able to pass the name of the new calculated variable in programmat
You could consider changing the column names inside your function:
groupMeans <- function(out.var, by.var, dat = dt) { res <- dat[, list(mean(x)), by=by.var] setnames(res, "V1", out.var) res }