You can use table
and prop.table
:
> prop.table(table(subdata), 2)
soda
gender n y
f 0.2 0.8
m 0.8 0.2
The function table
counts the values per combination. prop.table
calculates relative frequencies along the second margin (i.e., 2
: columns).