interact | R Documentation |
Allows multiple grouping by multiple variables as if they were a single
variable, which allows calculating proportions that sum to 100
more than a single grouping variable with survey_mean
.
interact(...)
... |
variables to group by. All types of tbls accept variable names, and most will also accept functions of variables (though some database-backed tbls do not allow creating variables). |
Behind the scenes, this function creates a special column type that is
split back into the component columns automatically by summarize
.
A vector of type srvyr_interaction
, which is generally
expected to be automatically split apart.
data(api, package = "survey")
dstrata <- apistrat %>%
as_survey_design(strata = stype, weights = pw)
# The sum of the whole prop column is equal to 100%
dstrata %>%
group_by(interact(stype, awards)) %>%
summarize(prop = survey_mean())
# But if you didn't interact, the sum of each stype's prop is 100%
dstrata %>%
group_by(stype, awards) %>%
summarize(prop = survey_mean())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.