Copies variable labels, value labels, and tagged NA metadata from a source
data frame to a target data frame. This is essential after dplyr operations
like dplyr::filter(), dplyr::select(), or dplyr::mutate() which can
strip label attributes.
Value
The target data frame with labels copied from the source. Only columns present in both data frames are affected. Columns only in the target are left unchanged.
Details
The following attributes are copied for each shared column:
"label"— variable label"labels"— value labels"na_tag_map"— tagged NA mapping"na_tag_format"— tagged NA format (spss/stata/sas)"class"— vector class (e.g.,haven_labelled)
See also
Other labels:
drop_labels(),
find_var(),
set_na(),
to_character(),
to_label(),
to_labelled(),
to_numeric(),
unlabel(),
val_labels(),
var_label()
Examples
# Labels are lost after dplyr operations
data_subset <- dplyr::filter(survey_data, age >= 18)
# Restore them
data_subset <- copy_labels(data_subset, survey_data)
