I have a data.table
that looks like the following:
x, y, sum(count)
1, 1, 3
1, 2, 7
1, 3, 8
2, 1, 4
2, 2, 3
2, 3, 10
And so on. It's keyed by x
and y
and I did a sum
on a count
column. I would like to break it down into percentages by the values of x so that it becomes:
x, y, percentage(counts)
1, 1, 16.7
1, 2, 38.9
1, 3, 44.4
2, 1, 23.5
2, 2, 17.6
2, 3, 58.8
So that the total percentage per x
value totals 100%. I am doing this using the data.table
package. Thank you in advance for your help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…