table_weightedpct {whomds} | R Documentation |
Calculate table of percentages or N of response distribution for survey items, survey weighted, disaggregated
Description
Calculate table of percentages or N of response distribution for survey items, survey weighted, disaggregated
Usage
table_weightedpct(
df,
vars_ids,
vars_strata,
vars_weights,
formula_vars,
...,
formula_vars_levels = 0:1,
by_vars = NULL,
pct = TRUE,
willfilter = NULL,
add_totals = FALSE,
spread_key = NULL,
spread_value = "prop",
arrange_vars = NULL,
include_SE = FALSE
)
Arguments
df |
a data frame of individual survey data, where each row is an individual |
vars_ids |
a character vector of cluster ids, passed to |
vars_strata |
a character vector of strata ids, passed to |
vars_weights |
a character vector of survey weight ids, passed to |
formula_vars |
a character vector of variables to calculate the percentages of each level for |
... |
captures expressions to pass to |
formula_vars_levels |
a vector of the levels of the the |
by_vars |
a character vector of variables to disaggregate results by. Default is |
pct |
a logical variable indicating whether or not to calculate weighted percentages. Default is |
willfilter |
a logical variable that tells the function whether or not to filter or transmute the data. Leave as default |
add_totals |
logical determining whether to create total rows or columns (as appropriate) that demonstrate the margin that sums to 100. Default is FALSE. |
spread_key |
a string with variable name to pass to |
spread_value |
a string with variable name to pass to |
arrange_vars |
a character vector with variables to pass to |
include_SE |
a logical variable indicating whether to include the standard errors in the table. Default is FALSE. Currently does not work when adding totals, spreading or transmuting. |
Details
If willfilter
is NULL, the table is not filtered or transmuted. If willfilter
is TRUE, the table is filtered before it is spread or arranged. If willfilter
is FALSE, the table is transmuted after the spread and/or arrange. "..." captures the non-standard evaluation expressions (NSE) to pass to dplyr::filter
or dplyr::transmute()
.
The function performs the following actions with the table after results are calculated in the following order (if applicable): filter, add totals, spread, arrange, transmute
Value
a tibble of weighted response percentages or N's
See Also
See vignette("programming", package = "dplyr")
for more about non-standard evaluation (NSE)
Other table functions:
table_basicstats()
,
table_unweightedpctn()
Examples
table_weightedpct(df_adults,
vars_ids = c("HHID", "PSU"),
vars_strata = "strata",
vars_weights = "weight",
formula_vars = paste0("EF",1:10),
formula_vars_levels = 1:5,
by_vars = "sex")