Description Usage Arguments Details Examples
This function forces values the variables in .var
to take constant values within combinations of the variables in .within
. fixed_force()
will return a data frame with consistency enforced.
1 2 3 4 5 6 7 | fixed_force(
.df,
.var = NULL,
.within = NULL,
.resolve = mode_order,
.flag = NA
)
|
.df |
Data frame, pibble, or tibble. |
.var |
Quoted or unquoted variable(s) in |
.within |
Quotes or unquoted variable(s) that the |
.resolve |
Function capable of being passed to |
.flag |
String indicating the name of a new variable that flags any observations altered by |
Inconsistencies will be resolved by the function .resolve
. Or, set .resolve
to 'drop'
(or any string, really) to drop all cases with inconsistency.
1 2 3 4 5 6 7 8 9 10 11 12 13 | data(Scorecard)
# The variables pred_degree_awarded_ipeds and state_abbr should be constant within unitid
# However, sometimes colleges change what they offer.
# For the purpose of my analysis, though,
# I want to treat any changers as whatever they are most often (the mode).
# So let's enforce that with fixed_force
Scorecard <- fixed_force(Scorecard,
.var = c(pred_degree_awarded_ipeds, state_abbr),
.within = unitid, .flag = "changed"
)
# Did we catch any changers?
table(Scorecard$changed)
# We did!
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.