Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

tidy_add_variable_labels

Add variable labels


Description

Will add variable labels in a var_label column, based on:

  1. labels provided in labels argument if provided;

  2. variable labels defined in the original data frame with the label attribute (cf. labelled::var_label());

  3. 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 x

quiet

logical argument whether broom.helpers should not return a message when requested output cannot be generated. Default is FALSE

strict

logical argument whether broom.helpers should return an error when requested output cannot be generated. Default is FALSE

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

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"
    )
  )

broom.helpers

Helpers for Model Coefficients Tibbles

v1.3.0
GPL-3
Authors
Joseph Larmarange [aut, cre] (<https://orcid.org/0000-0001-7097-700X>), Daniel D. Sjoberg [aut] (<https://orcid.org/0000-0003-0862-2018>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.