I have a table and I would like to calculate the percentage of each value on the sum of each column. I mean I would like to have these data:
(30/35)x100, (0/35)x100, (5/35)x100 for the first column, (3/29)x100, (24/29)x100, (2/29)x100 and (5/19)x100, (7/19)x100, (7/19)x100 for the third column.
df
Donkey Horse Hybrid
Donkey 30 3 5
Horse 0 24 7
Hybrid 5 2 7
I used this function but the calculation is not correct.
apply(df, 2,function(x,y) (x/y)*100, colSums(df))
Could anyone help please? Many thanks in advance