crosstab_3way: weighted 3-way crosstabs

Description Usage Arguments Details Value Examples

View source: R/Crosstab3way.R

Description

crosstab_3way returns a tibble containing a weighted crosstab of two variables by a third variable

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
crosstab_3way(
  df,
  x,
  y,
  z,
  weight,
  remove = c(""),
  n = TRUE,
  pct_type = "row",
  format = "wide",
  unwt_n = FALSE
)

Arguments

df

The data source

x

The independent variable

y

The dependent variable

z

The second control 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.

pct_type

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

format

one of "long" or "wide"

unwt_n

logical, if TRUE a column is added containing unweighted frequency counts

Details

Options include row or cell percentages. The tibble can be in long or wide format. These tables are ideal for use with small multiples created with ggplot2::facet_wrap.

Value

a tibble

Examples

1
2
3
crosstab_3way(df = illinois, x = sex, y = educ6, z = maritalstatus, weight = weight)
crosstab_3way(df = illinois, x = sex, y = educ6, z = maritalstatus, weight = weight,
format = "wide")

Example output

# A tibble: 6 x 9
  sex    maritalstatus    `LT HS`    HS `Some Col`    AA    BA `Post-BA`       n
  <fct>  <fct>              <dbl> <dbl>      <dbl> <dbl> <dbl>     <dbl>   <dbl>
1 Male   Married             8.63  29.9       17.2  7.99  21.8     14.4   2.80e7
2 Male   Widow/divorced/14.9   35.7       20.6  7.64  13.6      7.52  6.11e6
3 Male   Never Married      12.6   31.3       27.2  6.51  17.9      4.53  1.50e7
4 Female Married             7.01  30.5       18.0  9.25  22.5     12.7   2.70e7
5 Female Widow/divorced/17.7   35.2       20.2  8.37  11.4      7.19  1.25e7
6 Female Never Married      10.3   25.0       29.9  7.27  20.0      7.56  1.41e7
# A tibble: 6 x 9
  sex    maritalstatus    `LT HS`    HS `Some Col`    AA    BA `Post-BA`       n
  <fct>  <fct>              <dbl> <dbl>      <dbl> <dbl> <dbl>     <dbl>   <dbl>
1 Male   Married             8.63  29.9       17.2  7.99  21.8     14.4   2.80e7
2 Male   Widow/divorced/14.9   35.7       20.6  7.64  13.6      7.52  6.11e6
3 Male   Never Married      12.6   31.3       27.2  6.51  17.9      4.53  1.50e7
4 Female Married             7.01  30.5       18.0  9.25  22.5     12.7   2.70e7
5 Female Widow/divorced/17.7   35.2       20.2  8.37  11.4      7.19  1.25e7
6 Female Never Married      10.3   25.0       29.9  7.27  20.0      7.56  1.41e7

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