crosstab | R Documentation |
crosstab
returns a tibble containing a weighted crosstab of two variables
crosstab(
df,
x,
y,
weight,
remove = "",
n = TRUE,
pct_type = "row",
format = "wide",
unwt_n = FALSE
)
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" |
Options include row, column, or cell percentages. The tibble can be in long or wide format.
a tibble
crosstab(df = illinois, x = voter, y = raceethnic, weight = weight)
crosstab(df = illinois, x = voter, y = raceethnic, weight = weight, n = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.