r - How to aggregate (using "by") a data.table with customized column name without ":="? -
i know can this
<- dt[,sum(x), by=y]
also can this
dt[,z:=sum(x), by=y] # modify dt
however don't why cannot this:
<- dt[,z=sum(x), by=y]
how should perform "summarize" customized column names?
is option?
<- copy(dt) a[,z:=sum(x), by=y]
you're looking list()
in j
argument:
a <- dt[,list(z=sum(x)), by=y]
Comments
Post a Comment