table_unweightedpctn function

Compute unweighted percent and N for multiple variables, disaggregated

Compute unweighted percent and N for multiple variables, disaggregated

table_unweightedpctn( df, vars_demo, group_by_var = NULL, spread_by_group_by_var = FALSE, group_by_var_sums_to_100 = FALSE, add_totals = FALSE )

Arguments

  • df: a data frame of individual survey data, where each row is an individual
  • vars_demo: a character vector of names of variables to calculate percent and N for
  • group_by_var: a string (length 1) with the name of the variable from df to disaggregate by
  • spread_by_group_by_var: logical determining whether to pass group_by_var to tidyr::pivot_wider() to give a wide-format tab. Default is FALSE.
  • group_by_var_sums_to_100: logical determining whether percentages sum to 100 along the margin of group_by_var, if applicable. Default is FALSE.
  • add_totals: logical determining whether to create total rows or columns (as appropriate) that demonstrate the margin that sums to 100. Default is FALSE.

Returns

A tibble with percent and N for each level of each variable in vars_demo

Examples

table_unweightedpctn(df_adults, vars_demo = c("sex", "age_cat", "work_cat", "edu_cat")) table_unweightedpctn(df_adults, vars_demo = c("sex", "age_cat", "work_cat", "edu_cat"), group_by_var = "disability_cat") table_unweightedpctn(df_adults, vars_demo = c("sex", "age_cat", "work_cat", "edu_cat"), group_by_var = "disability_cat", spread_by_group_by_var = TRUE)

See Also

Other table functions: table_basicstats(), table_weightedpct()