crosstab: weighted crosstabs

Description Usage Arguments Details Value Examples

View source: R/Crosstab.R

Description

crosstab returns a tibble containing a weighted crosstab of two variables

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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

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

Example output

# A tibble: 2 x 6
  voter     White Black Hispanic Other         n
  <fct>     <dbl> <dbl>    <dbl> <dbl>     <dbl>
1 Voted      76.4  15.5     5.48  2.61 56230937.
2 Not voted  74.1  10.8    10.3   4.83 32070164.
# A tibble: 2 x 5
  voter     White Black Hispanic Other
  <fct>     <dbl> <dbl>    <dbl> <dbl>
1 Voted      76.4  15.5     5.48  2.61
2 Not voted  74.1  10.8    10.3   4.83

pollster documentation built on Aug. 25, 2020, 5:08 p.m.