# Load in example dataset d
data(d)
# Create labels for treatment group, sex, and race
groups = c("Control","Treatment")
sexes = c("Female","Male")
races = c("White","Black","Mexican American","Other")
# Compare sex distribution by group, with group as column variable
freqtable1 = tabfreq(x=d$group,y=d$sex,xlevels=groups,ylevels=sexes,yname="Sex")
# Same comparison, but compress table to single row
freqtable2 = tabfreq(x=d$group,y=d$sex,xlevels=groups,yname="Male",compress=TRUE)
# Compare sex distribution by race, with race as column variable, and omit sample sizes
freqtable3 = tabfreq(x=d$race,y=d$sex,xlevels=races,yname="Sex",ylevels=sexes,n=FALSE)
# Use rbind to create single table comparing sex and race in control vs. treatment group
freqtable4 = rbind(tabfreq(x=d$group,y=d$sex,xlevels=groups,ylevels=sexes,yname="Sex"),
tabfreq(x=d$group,y=d$race,xlevels=groups,ylevels=races,yname="Race"))
# Click on freqtable1, freqtable2, freqtable3, and freqtable4 in the Workspace tab of
# RStudio to see the tables that could be copied and pasted into a report or manuscript.
Run the code above in your browser using DataLab