I have two weeks experience in R and will appreciate your help.
I have a data table that was constructed with count(), and I want to calculate the percentage of the frequencies by categories. So if this is my data frame:
name cat1 cat2 freq
A 1 1 32
A 1 0 56
A 0 1 36
A 0 0 25
B 1 1 14
B 1 0 68
B 0 1 58
B 0 0 90
I want to calculate the percentage by name and by cat1 (cat2 = 1,0 is the total). I have a number of data frames, for some of the names it could be that only cat1=0 & cat2=0, and because of the different structures I don't can't do it straightforward.
For example, the first line will be (32/(32+56))*100, the fourth (25/(25+36))*100.
Any ideas?
Thanks