| Title: | Weighted Cross-Tabulations Exported to 'Excel' |
| Version: | 0.1.3 |
| Description: | Produces weighted cross-tabulation tables for one or more outcome variables across one or more breakdown variables, and exports them directly to 'Excel'. For each outcome-by-breakdown combination, the package creates a weighted percentage table and a corresponding unweighted count table, with transparent handling of missing values and light, readable formatting. Designed to support social survey analysis workflows that require large sets of consistent, publication-ready tables. |
| Language: | en-GB |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| Imports: | haven, openxlsx, stats |
| RoxygenNote: | 7.3.3 |
| URL: | https://github.com/smmcandrew/tabbitR |
| BugReports: | https://github.com/smmcandrew/tabbitR/issues |
| Suggests: | knitr, rmarkdown |
| VignetteBuilder: | knitr |
| NeedsCompilation: | no |
| Packaged: | 2026-02-05 21:46:01 UTC; siobh |
| Author: | Siobhan McAndrew [aut, cre] |
| Maintainer: | Siobhan McAndrew <siobhan.mcandrew@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-02-09 13:50:02 UTC |
Write Weighted Crosstab Tables To An Excel Workbook
Description
tabbit_excel() produces weighted percentage tables and unweighted counts
for one or more outcome variables, optionally including missing responses
and/or row percentages. Output is written to an Excel file with one sheet per
breakdown variable by default (or all results in a single sheet if
by_breakdown = FALSE).
Usage
tabbit_excel(
data,
vars,
breakdown,
file,
wtvar,
row_pct = FALSE,
decimals = 1L,
nooverall = FALSE,
nototal = FALSE,
missingasrow = FALSE,
nomissing = FALSE,
by_breakdown = TRUE,
sheet_base = "Frequencies",
...
)
Arguments
data |
A data frame. |
vars |
Character vector of outcome variable names. |
breakdown |
Character vector of breakdown variables. |
file |
Path to the Excel file to create. |
wtvar |
Name of the weight variable (string). Must be present in |
row_pct |
Logical. If |
decimals |
Integer. Number of decimal places for percentages (0-6; default 1). |
nooverall |
Logical. If |
nototal |
Logical. If |
missingasrow |
Logical. If |
nomissing |
Logical. If |
by_breakdown |
Logical. If |
sheet_base |
Sheet name to use when |
... |
For future extension. |
Details
For each outcome variable in vars and each breakdown variable in
breakdown, tabbit_excel():
computes weighted percentages (by column or by row),
optionally adds an overall distribution across breakdowns,
optionally adds a "Total percent" row (column mode only),
handles missing outcomes either as a separate "Response missing" row or by excluding them, with or without a separate "Missing percent" line, and
writes a corresponding unweighted N table including (or excluding) missing responses.
A light formatting layer is applied using the openxlsx package:
table headers: bold, with top and bottom borders,
row labels: bold,
total rows ("Total percent" and "Column totals"): bold, with top and bottom borders, and
missing-percentage row: italic.
Value
Invisibly, the file path of the created workbook (a character string).
Examples
out_file <- tempfile(fileext = ".xlsx")
df <- data.frame(
courteous = factor(c("Definitely true","Mostly true", NA, "Mostly false")),
listener = factor(c("Often","Sometimes","Never", NA)),
sex = factor(c("Male","Female","Female","Male")),
agegrp1 = factor(c("18-34","35-54","18-34","55+")),
weight = c(1, 1.5, 0.8, 1.2)
)
tabbit_excel(
data = df,
vars = c("courteous", "listener"),
breakdown = c("sex", "agegrp1"),
file = out_file,
wtvar = "weight",
row_pct = FALSE,
decimals = 1L,
nooverall = FALSE,
nototal = FALSE,
missingasrow = FALSE,
nomissing = FALSE
)