# NOT RUN {
data("tobacco")
ctable(tobacco$gender, tobacco$smoker)
# Use with() to simplify syntax
with(tobacco, ctable(smoker, diseased))
# Show column proportions, without totals
with(tobacco, ctable(smoker, diseased, prop = "c", totals = FALSE))
# Simple 2 x 2 table with odds ratio and risk ratio
with(tobacco, ctable(gender, smoker, totals = FALSE, headings = FALSE, prop = "n",
OR = TRUE, RR = TRUE))
# Grouped cross-tabulations
with(tobacco, stby(data = list(x = smoker, y = diseased),
INDICES = gender, FUN = ctable))
# }
# NOT RUN {
ct <- ctable(tobacco$gender, tobacco$smoker)
# Show html results in browser
print(ct, method = "browser")
# Save results to html file
print(ct, file = "ct_gender_smoker.html")
# Save results to text file
print(ct, file = "ct_gender_smoker.txt")
# }
Run the code above in your browser using DataLab