I'm trying to create a summarized data.table using the j column, but assign to a name stored in a variable.
For example, I can do this:
x = data.table(c(1,2,3,4,5,6),c(2,2,2,3,3,3))
x[,.("a" = mean(V1), "b" = max(V1)),by=V2]
which returns as wanted
V2 a b
1: 2 2 3
2: 3 5 6
Now instead of using the name "a", I would like to use a variable name:
varname = "a"
x[,.(varname = mean(V1), "b" = max(V1)), by=V2]
I'd like it to return the same output, but of course here column a is labeled as "varname". I've tried using eval, get, and others and haven't figured out the right syntax. Is this built in, or will I have to relabel the name outside of data.table?