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