crosstab: weighted crosstabs

View source: R/Crosstab.R

crosstabR Documentation

weighted crosstabs

Description

crosstab returns a tibble containing a weighted crosstab of two variables

Usage

crosstab(
  df,
  x,
  y,
  weight,
  remove = "",
  n = TRUE,
  pct_type = "row",
  format = "wide",
  unwt_n = FALSE
)

Arguments

df

The data source

x

The independent variable

y

The dependent variable

weight

The weighting variable

remove

An optional character vector of values to remove from final table (e.g. "refused"). This will not affect any calculations made. The vector is not case-sensitive.

n

logical, if TRUE numeric totals are included. They are included in a separate column for row and cell percentages, but in a separate row for wide format column percentages.

pct_type

Controls the kind of percentage values returned. One of "row," "cell," or "column."

format

one of "long" or "wide"

unwt_n

logical, if TRUE a column "unweighted_n" is included containing the unweighted frequency count. It is not available when pct_type is "column"

Details

Options include row, column, or cell percentages. The tibble can be in long or wide format.

Value

a tibble

Examples

crosstab(df = illinois, x = voter, y = raceethnic, weight = weight)
crosstab(df = illinois, x = voter, y = raceethnic, weight = weight, n = FALSE)

jdjohn215/pollster documentation built on May 19, 2023, 4:34 p.m.