wtd_tab: Create weighted frequency table with multiple row variables

Description Usage Arguments Details Value See Also Examples

Description

Generate combined weighted frequency tables for multiple x-axis variables, both for oneway and two-way tables.

Usage

1
2
3
wtd_tab(data, xvars, yvar = NULL, weights = NULL,
  normwt = getOption("MC.normwt"), nowt.show = getOption("MC.nowt.show"),
  dem.table = FALSE, top.table = FALSE)

Arguments

data

a data frame containing the variables to use in the table.

xvars

character: vector of variable names in data for x-axis rows.

yvar

character: response variable for the y-axis in a two-way table.

weights

character: column name in data containing the sample weights.

normwt

logical: if TRUE, normalize weights so that the total weighted count is the same as the unweighted one. Defaults to options(MC.normwt).

nowt.show

logical: if TRUE, include unweighted registered voter statistics at the end of the table. Defaults to options(MC.nowt.show).

dem.table

logical: if TRUE, creates data for a demographic summary table.

top.table

logical: if TRUE, creates data for a topline table.

Details

An updated version of the wtd_table function from the questionr package with the added functionality of taking multiple vectors as the x argument. Additionally produces rownames for the resulting table using the levels of the variables passed to xvars and column names using the levels of the variable passed to yvar.

Value

If yvar is not provided, returns a weighted one-way frequency table of xvars. Otherwise, returns a weighted two-way frequency table of xvars and yvar.

See Also

wtd_table

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Regular two-way frequency table
wtab1 <- wtd_tab(data, listVars, vars[3], 'wts')
wtab1

# Demographic frequency table
wtab2 <- wtd_tab(data, listVars, NULL, 'wts', dem.table = TRUE)
wtab2

# Topline frequency table
wtab3 <- wtd_tab(data, vars, 'xdemAll', 'wts', top.table = TRUE)
wtab3

alexdulin/MCmrp documentation built on May 11, 2019, 11:29 p.m.