You can build 2 types of contingency tables.
One way table -
table() returns simple frequency counts
Ex:
> table(mpg$cyl)
4 5 6 8
81 4 79 70
prop.table() returns the frequemcy in terms on proportion.
Ex:
> prop.table(table(mpg$cyl))
4 5 6 8
0.34615385 0.01709402 0.33760684 0.29914530
Two way tables -
table(var1,var2) returns count in row and column values.
Ex:
table(mpg$cyl,mpg$year)
1999 2008
4 45 36
5 0 4
6 45 34
8 27 43
xtabs() - returns a contingency table like table().
Here var1+var2 are the variables used to perform the table are calculated wrt full data frame.
Ex:
xtabs(~cyl+year,mpg)
year
cyl 1999 2008
4 45 36
5 0 4
6 45 34
8 27 43
You can see both frequency count and proportion using margin.table(table object)