
Generate Crosstabulation of Exposure and Response Variables
Source:R/population_analysis.R
summary_exp_resp_crosstabulation.RdThis function produces a cross-tabulation summary between two variables, `exposure` and `response`, from a given dataset. It returns either a styled HTML table for interactive viewing or a Word-compatible `flextable` for document output.
Value
An object of class `sjTable` (if `output = "viewer"`) or a `flextable` (if `output = "docx"`).
Details
- When `output = "viewer"`, the function returns a formatted HTML table with row percentages using `sjPlot::tab_xtab()`. - When `output = "docx"`, the cross-tabulation is converted to a data frame using `sjtable2df::xtab2df()` and formatted using `flextable` for inclusion in Word documents.
Examples
if (FALSE) { # \dontrun{
# Example data
df <- data.frame(
exposure = sample(c(0, 1), 100, replace = TRUE),
response = sample(c(0, 1), 100, replace = TRUE)
)
summary_exp_resp_crosstabulation(df, output = "viewer")
ft <- summary_exp_resp_crosstabulation(df, output = "docx")
} # }