Can I print something while grouping a data.table?

Viewed 270

Let's say I have this data.table:

dt=data.table(ID=letters[seq(3,8)],category=rep(c('a','b'),each=3),value=seq(1,6))

I want to get the relative percentage of the value of each register relative to the sum of all values in a category. Besides that, I would like to print the category for debugging reasons. It would be something like this:

dt[,print(.BY[["category"]]),
    list(relative=value/sum(dt[category==.BY[["category"]],value],
    by='ID')

Thank you

1 Answers
Related