# Frequency Distribution by Groups

#### Yankel

##### Member
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

prop.table(table(diet$Diet, diet$Gender))
prop.table(table(diet$Diet, diet$Gender), margin = 1)
prop.table(table(diet$Diet, diet$Gender), margin = 2)