Setting column name in "group by" operation with data.table
DT[,list(z=sum(y)+3,a=mean(y*z)),by=x]
x z a
1: a 6 9
2: b 15 60
Since you are new to data.table
, I recommend that you also study the help page of the setnames
function as well as ?data.table
and the data.table
vignettes.
For conciseness, you can now use .()
instead of list()
DT[, .(z=sum(y)+3, a=mean(y*z)), by=x]