nice_frequencies.RdThis function creates a frequency table for a given variable, optionally grouped by another variable. It can include counts, percentages, and totals, with customizable labels and formatting options.
nice_frequencies(
data,
grouping = NULL,
label = NULL,
label_grouping = NULL,
show_missing = TRUE,
show_percent = TRUE,
percent_base = "column",
show_total_col = TRUE,
show_total_row = TRUE,
auto_labels = TRUE,
title = NULL,
footnote = NULL,
file = NULL,
round = 1,
...
)Vector.
A grouping variable as a vector.
Set label for the variable name.
Set label for the grouping variable name.
If TRUE, adds a row for the number of missing values.
If TRUE, adds a column for percentages.
If show_percent is TRUE, this argument specifies the base for percentage calculations. Options are "column" (percentages calculated within each column), "row" (percentages calculated within each row), or "total" (percentages calculated based on the total count). Default is "column".
If TRUE, adds a column with the total counts and percentages (if show_percent is TRUE).
If TRUE, adds a row with the total counts and percentages (if show_percent is TRUE).
If TRUE, variable names are taken from a label attribute.
Table title.
Table footnote.
Filename.
Further arguments passed to nice_table().
An html table with frequencies
The resulting data frame contains the frequency counts and, if specified, the
percentages for each level of the variable and grouping variable. The table can
also include totals for rows and columns, and a row for missing values if desired.
The resulting data frame is decorated with attributes for use with the
wmisc::nice_table() function, which is called internally to create the final
output.
nice_frequencies(mtcars_labeled[[11]])
Table
Frequency statistics of ‘Number of carburetors’
Number of carburetors
Frequency
Percent
## cross table
nice_frequencies(
mtcars_labeled$cyl,
mtcars_labeled$am
)
Table
Frequency statistics of ‘Number of cylinders’ by ‘Transmission Type’
0
1
Total
0
1
Total
Note. Percentages are calculated within columns.
## barebone table
nice_frequencies(
mtcars_labeled$cyl,
mtcars_labeled$am,
show_missing = FALSE,
show_percent = FALSE,
show_total_col = FALSE,
show_total_row = FALSE
)
Table
Frequency statistics of ‘Number of cylinders’ by ‘Transmission Type’
0
nice_frequencies(
mtcars_labeled$cyl,
mtcars_labeled$am,
label = "Cylinders",
label_grouping = "Transmission",
title = "Cylinders by Transmission Type"
)
Table
Cylinders by Transmission Type
0
1
Total
0
1
Total
Note. Percentages are calculated within columns.