Frequency Distribution by Groups

#1
Hello all,

I am trying to get a frequency table by group in R, similar to what PROC TABULATE gives in SAS.

I have tried:

Code:
temp = table(diet$Diet,diet$Gender)
And it gives me a table of frequencies for the diet variable by Gender. However, it gives no percentages, just the frequencies themselves which are not informative at all. How do I get a proper frequency table ?

The diet variable has 3 levels: 1,2,3. For each level, I wish to get a frequency and percentage of each gender, and an overall (100%). In other words, I wish the summing to be by row. Can it be done ?
 

Dason

Ambassador to the humans
#2
Look into prop.table.

Code:
prop.table(table(diet$Diet, diet$Gender))
# if you want row margin percents
prop.table(table(diet$Diet, diet$Gender), margin = 1)
# if you want column margin percents
prop.table(table(diet$Diet, diet$Gender), margin = 2)