Internal helper function to relevel specified factor variables in a data frame using user-defined reference values.
Value
The original data frame with specified factor variables releveled to the given reference. If a variable is not found in the data frame, a warning is issued and the variable is skipped.
Details
This function is typically used before modeling to ensure that categorical variables have the appropriate reference level, particularly when computing contrasts in regression models.
Examples
if (FALSE) { # \dontrun{
df <- data.frame(group = factor(c("A", "B", "A", "C")))
ref_vals <- list(group = "B")
df <- .relevel_by_reference(df, ref_vals)
levels(df$group) # "B" will now be the reference level
} # }
