I know I can do this
a <- dt[,sum(x), by=y]
Also I can do this
dt[,z:=sum(x), by=y] # this would modify dt
However I don't get why I cannot do this:
a <- dt[,z=sum(x), by=y]
How should I perform a "summarize" with customized column names?
Is this the only option?
a <- copy(dt)
a[,z:=sum(x), by=y]
You're looking for list()
in the j
argument:
a <- dt[,list(z=sum(x)), by=y]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With