single_table {surveyexplorer}R Documentation

Create a table of frequencies and counts for single-choice questions

Description

Generates a detailed table summarizing the frequencies and counts for each level of the specified variable, question. If a grouping variable, group_by, is provided, the table extends to include row and column totals, along with additional count and frequency columns for each level of group_by (excluding specified subgroups, if any). When survey weights are specified with weights, the counts reflect the weighted values, and a note is appended at the bottom of the table.

Usage

single_table(
  dataset,
  question,
  group_by = NULL,
  subgroups_to_exclude = NULL,
  weights = NULL,
  na.rm = FALSE
)

Arguments

dataset

The input dataframe (or tibble) of survey questions

question

The categorical variable of interest for which frequencies and counts will be calculated, can be selected by using tidyselect semantics

group_by

Optional variable to group the analysis. If provided, the frequencies and counts will be calculated within each subgroup.

subgroups_to_exclude

Optional vector specifying subgroups to exclude from the analysis.

weights

Optional variable containing survey weights. If provided, frequencies and counts will be weighted accordingly.

na.rm

Logical indicating whether to remove NA values from question before analysis.

Value

A gt table summarizing frequencies and counts based on the specified parameters. If the optional group_by parameter is provided, the output will be a grouped gt table, displaying frequencies and counts for each subgroup as well as row and column totals.

See Also

Other single-choice questions: single_freq(), single_summary()

Examples

#Simple table
single_table(berlinbears, question = income)

#Use `group_by` to partition the question into several groups
single_table(berlinbears, question = income, group_by = gender)

#to ignore a subgroup, use `subgroups_to_exclude`
single_table(berlinbears, question = income, group_by = species,
subgroups_to_exclude = c('black bear', NA))

#Specifiy survey weights with `weights`
 single_table(berlinbears, question = h_winter, group_by = gender,
 weights = weights)

#to ignore NA values in the responses to `question`, set na.rm = TRUE
single_table(berlinbears, question = h_winter, na.rm = TRUE)



[Package surveyexplorer version 0.1.0 Index]