update_variable_labels_with | R Documentation |
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(), ...)
.data |
A data frame, or data frame extension (e.g. a tibble) |
.fn |
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 |
For update_variable_labels_with()
, it is possible to access the name of
the variable inside .fn
by using names()
, i.e. .fn
receive a named
character vector (see example). .fn
can return as.character(NA)
to
remove a variable label.
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()
df %>%
update_variable_labels_with(toupper) %>%
look_for()
# accessing variable names with names()
df %>%
update_variable_labels_with(function(x){tolower(names(x))}) %>%
look_for()
df %>%
update_variable_labels_with(toupper, .cols = dplyr::starts_with("S")) %>%
look_for()
df %>%
update_value_labels_with(toupper) %>%
look_for()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.