| tidy_add_variable_labels {broom.helpers} | R Documentation |
Add variable labels
Description
Will add variable labels in a var_label column, based on:
labels provided in
labelsargument if provided;variable labels defined in the original data frame with the
labelattribute (cf.labelled::var_label());variable name otherwise.
Usage
tidy_add_variable_labels(
x,
labels = NULL,
interaction_sep = " * ",
model = tidy_get_model(x),
quiet = FALSE,
strict = FALSE
)
Arguments
x |
a tidy tibble |
labels |
an optional named list or named vector of custom variable labels |
interaction_sep |
separator for interaction terms |
model |
the corresponding model, if not attached to |
quiet |
logical argument whether broom.helpers should not return
a message when requested output cannot be generated. Default is |
strict |
logical argument whether broom.helpers should return an error
when requested output cannot be generated. Default is |
Details
If the variable column is not yet available in x,
tidy_identify_variables() will be automatically applied.
It is possible to pass a custom label for an interaction
term in labels (see examples).
See Also
Other tidy_helpers:
tidy_add_coefficients_type(),
tidy_add_contrasts(),
tidy_add_estimate_to_reference_rows(),
tidy_add_header_rows(),
tidy_add_n(),
tidy_add_pairwise_contrasts(),
tidy_add_reference_rows(),
tidy_add_term_labels(),
tidy_attach_model(),
tidy_disambiguate_terms(),
tidy_identify_variables(),
tidy_plus_plus(),
tidy_remove_intercept(),
tidy_select_variables()
Examples
df <- Titanic %>%
dplyr::as_tibble() %>%
dplyr::mutate(Survived = factor(Survived, c("No", "Yes"))) %>%
labelled::set_variable_labels(
Class = "Passenger's class",
Sex = "Sex"
)
df %>%
glm(Survived ~ Class * Age * Sex, data = ., weights = .$n, family = binomial) %>%
tidy_and_attach() %>%
tidy_add_variable_labels(
labels = list(
"(Intercept)" = "Custom intercept",
Sex = "Gender",
"Class:Age" = "Custom label"
)
)