Learn R Programming

SciencesPo (version 1.3.7)

tabulate: Tabulate

Description

tabulate is a modified version of crosstable for printing a summary table with cell counts and column proportions (similar to STATA's tabulate varname1 varname2, col).

Usage

tabulate(x, y, digits = 2)

Arguments

x,y
The variables for the cross tabulation.
digits
The number of digits for rounding proportions.

See Also

xtabs, crosstable, table, prop.table

Examples

Run this code
# 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