Skip to contents

Some functions don't work with labelled variables. As a solution, this function can be used to drop labels (and all other attributes) from one or more variables within a data frame, from all variables if none are specified, or from a vector directly.

Usage

drop_label(x, ...)

Arguments

x

A data frame or a vector/column.

...

When x is a data frame, select variables using tidyselect helpers (e.g., contains(), starts_with()) or unquoted names. If empty, removes labels from ALL variables. Ignored when x is a vector.

Value

The modified data frame or vector with attributes removed.

Examples

if (FALSE) { # \dontrun{
# Dataset-level: Remove labels from ALL variables
df |> drop_label()

# Dataset-level: Remove labels from specific variables
df |> drop_label(employment, starts_with("dem_"))

# Variable-level: Use inside mutate
df |> mutate(name_first = drop_label(name_first))

# Variable-level: Use with across()
df |> mutate(across(c(age, income), drop_label))
} # }