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

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -