| tab_cross | R Documentation |
Create subsets of the survey using one variable, and tabulate another variable within each of the subsets. Interact two variables and tabulate.
tab_cross(vr, vrby, max_levels = getOption("surveytable.max_levels"))
tab_subset(
vr,
vrby,
lvls = c(),
test = FALSE,
alpha = 0.05,
p_adjust = FALSE,
drop_na = getOption("surveytable.drop_na"),
max_levels = getOption("surveytable.max_levels")
)
vr |
variable to tabulate |
vrby |
use this variable to subset the survey |
max_levels |
a categorical variable can have at most this many levels. Used to avoid printing huge tables. |
lvls |
(optional) only show these levels of |
test |
if |
alpha |
significance level for tests |
p_adjust |
adjust p-values for multiple comparisons? |
drop_na |
drop missing values ( |
tab_subset() creates subsets using the levels of vrby, and tabulates
vr in each subset. Optionally, only use the lvls levels of vrby.
vr can be categorical (factor or character), logical, or numeric.
tab_cross() crosses or interacts vr and vrby and tabulates the new
variable. Tables created using tab_subset() and tab_cross() have the same
counts but different percentages. With tab_subset(), percentages within each
subset add up to 100%. With tab_cross(), percentages across the entire
population add up to 100%. Also see var_cross().
test = TRUE performs a test of association between the two variables. Also
performs t-tests for all pairs of levels of vr and vrby.
test = "{LEVEL}", where {LEVEL} is a level of vr, performs a
conditional independence test to compare the proportion of
vr = "{LEVEL}" for different values of vrby.
A list of tables or a single table.
Other tables:
tab(),
tab_rate(),
tab_subset_rate(),
total(),
total_rate()
set_survey(namcs2019sv)
# For each SEX, tabulate AGER
tab_subset("AGER", "SEX")
# Same counts as tab_subset(), but different percentages.
tab_cross("AGER", "SEX")
# Numeric variables
tab_subset("NUMMED", "AGER")
# Hypothesis testing
tab_subset("NUMMED", "AGER", test = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.