Update variable/value labels with a function
update_variable_labels_with(.data, .fn, .cols = dplyr::everything(), ...)
update_value_labels_with(.data, .fn, .cols = dplyr::everything(), ...)
A data frame, or data frame extension (e.g. a tibble)
A function used to transform the variable/value labels of the
selected .cols
.
Columns to update; defaults to all columns. Use tidy selection.
additional arguments passed onto .fn
.
df <- iris %>%
set_variable_labels(
Sepal.Length = "Length of sepal",
Sepal.Width = "Width of sepal",
Petal.Length = "Length of petal",
Petal.Width = "Width of petal",
Species = "Species"
)
df$Species <- to_labelled(df$Species)
df %>% look_for()
#> pos variable label col_type missing values
#> 1 Sepal.Length Length of sepal dbl 0
#> 2 Sepal.Width Width of sepal dbl 0
#> 3 Petal.Length Length of petal dbl 0
#> 4 Petal.Width Width of petal dbl 0
#> 5 Species Species dbl+lbl 0 [1] setosa
#> [2] versicolor
#> [3] virginica
df %>%
update_variable_labels_with(toupper) %>%
look_for()
#> pos variable label col_type missing values
#> 1 Sepal.Length LENGTH OF SEPAL dbl 0
#> 2 Sepal.Width WIDTH OF SEPAL dbl 0
#> 3 Petal.Length LENGTH OF PETAL dbl 0
#> 4 Petal.Width WIDTH OF PETAL dbl 0
#> 5 Species SPECIES dbl+lbl 0 [1] setosa
#> [2] versicolor
#> [3] virginica
df %>%
update_variable_labels_with(toupper, .cols = dplyr::starts_with("S")) %>%
look_for()
#> pos variable label col_type missing values
#> 1 Sepal.Length LENGTH OF SEPAL dbl 0
#> 2 Sepal.Width WIDTH OF SEPAL dbl 0
#> 3 Petal.Length Length of petal dbl 0
#> 4 Petal.Width Width of petal dbl 0
#> 5 Species SPECIES dbl+lbl 0 [1] setosa
#> [2] versicolor
#> [3] virginica
df %>%
update_value_labels_with(toupper) %>%
look_for()
#> pos variable label col_type missing values
#> 1 Sepal.Length Length of sepal dbl 0
#> 2 Sepal.Width Width of sepal dbl 0
#> 3 Petal.Length Length of petal dbl 0
#> 4 Petal.Width Width of petal dbl 0
#> 5 Species Species dbl+lbl 0 [1] SETOSA
#> [2] VERSICOLOR
#> [3] VIRGINICA