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.

fixed_force(
.df,
.var = NULL,
.within = NULL,
.resolve = mode_order,
.flag = NA
)

## Arguments

.df Data frame, pibble, or tibble. Quoted or unquoted variable(s) in .df that should be consistent. If not specified, uses all variables in .df that are not in .within. Quotes or unquoted variable(s) that the .var variables should be consistent within. Function capable of being passed to dplyr::summarize() that will be used to resolve inconsistencies. Or, set to 'drop' or any string to drop all inconsistent observations. By default, this will return the mode (ties use the first observed value). String indicating the name of a new variable that flags any observations altered by fixed_force().

## Details

Inconsistencies will be resolved by the function .resolve. Or, set .resolve to 'drop' (or any string, really) to drop all cases with inconsistency.

## Examples


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)#>
#> FALSE  TRUE
#> 48392    53 # We did!