View source: R/generate_crosstab.R
| generate_crosstab | R Documentation |
Generate cross-tabulation
generate_crosstab(
data,
x,
...,
add_total = TRUE,
add_total_row = TRUE,
add_total_column = TRUE,
add_percent = TRUE,
as_proportion = FALSE,
percent_by_column = FALSE,
name_separator = "_",
label_separator = "__",
label_total = "Total",
label_total_column = NULL,
label_total_row = NULL,
label_na = "Not reported",
include_na = TRUE,
recode_na = "auto",
label_as_group_name = TRUE,
group_separator = " - ",
group_as_list = FALSE,
group_grand_total = FALSE,
group_grand_total_label = "All",
calculate_per_group = TRUE,
expand_categories = TRUE,
position_total = "bottom",
sort_column_names = TRUE,
collapse_list = FALSE,
convert_factor = FALSE,
metadata = NULL
)
A data frame or a list of data frames containing the cross-tabulation results. If group_as_list is TRUE, the output will be a list of data frames, one for each combination of grouping variable(s). Otherwise, a single data frame is returned. Each data frame includes counts and, if specified, percentages or proportions for each combination of x and the additional variables provided in ....
generate_frequency(), generate_output(), rename_label(), remove_label()
# Using built-in dataset `person_record`
# Basic usage
person_record |>
generate_crosstab(marital_status, sex)
# Multiple variables
person_record |>
generate_crosstab(
sex,
seeing,
hearing,
walking,
remembering,
self_caring,
communicating
)
# Grouping
person_record |>
dplyr::group_by(sex) |>
generate_crosstab(marital_status, employed, group_as_list = TRUE)
# # Percent or proportion by row or column
person_record |>
generate_crosstab(
marital_status,
sex,
percent_by_column = TRUE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.