# Agresti (2002), table 3.11, p. 106
# 1992 General Social Survey- Sex and Party affiliation
gss <- data.frame(
expand.grid(sex=c("female", "male"),
party=c("dem", "indep", "rep")),
count=c(279,165,73,47,225,191))
#Get it expanded
df <- gss[rep(1:nrow(gss), gss[["count"]]), ]
with(df, tabulate(sex, party))
# Agresti (2002), table 3.10, p. 106
# 1992 General Social Survey- Race and Party affiliation
gss <- data.frame(
expand.grid(Race=c("black", "white"),
party=c("dem", "indep", "rep")),
count=c(103,341,15,105,11,405))
df <- gss[rep(1:nrow(gss), gss[["count"]]), ]
with(df, tabulate(Race, party))
Run the code above in your browser using DataLab