Finding both count and average of a column in R data.table, after group by I have a data table of 5 columns. I want to do a group by on one column  and want to get the count of another column, id.

I do this in this way:  dt[,length(id),by=dt$cid].

If I also want to get sum of id, how do I proceed?
I tried this:

dt[,(sum(id) length(id)),by=dt$cid]


but it did not work. Could you please help out.

Thanks
If you want to get but the sum and length of id with data.table, you can do it like this:

dt[,.(total=sum(id), n=length(id)), by=cid]


You could even write this in shorter format with the .N operator of data.table:

dt[,.(total=sum(id), .N), by=cid]