I'm probably facing an easy probleme here, but I just can't get it to work. I have a data.table as such:
data.table(replicate(3,sample(1:100,5,rep=TRUE)))
V1 V2 V3
1: 80 56 33
2: 28 97 39
3: 50 30 38
4: 13 35 52
5: 55 1 68
And I'd like to calculate the percentage of each column attributing to the row sum as such:
V1 V2 V3 sum
1: 47 33 20 100
2: 17 59 24 100
3: 42 25 32 100
4: 13 35 52 100
5: 44 1 55 100
I tried to calculate the rowsum first and the individually divide each column by rowsum and round up. Is there a better way to do so?