Setting column name in “group by” operation with data.table

前端 未结 2 1715
天命终不由人
天命终不由人 2020-12-31 05:02

I am a new user of the data.table package in R. I am trying to give a name to the new column created by a \"group by\" command

> DT = data.table(x=rep(c(\         


        
2条回答
  •  借酒劲吻你
    2020-12-31 05:07

    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.

提交回复
热议问题