data_label: Label factor variables using metadata

View source: R/label_data.R

data_labelR Documentation

Label factor variables using metadata

Description

For each column of x, this function checks whether value labels exist in value_labels. If so, integer values are replaced with these value labels.

Usage

data_label(
  x,
  variables = names(x),
  value_labels = read_yaml(paste0("value_labels_", substitute(x), ".yml"))
)

Arguments

x

A data.frame.

variables

Column names of x to replace, Default: names(x)

value_labels

A list with value labels, typically read from metadata generated by open_data or closed_data. Default: read_yaml(paste0("value_labels_", substitute(x), ".yml"))

Value

A data.frame.

Examples

## Not run: 
if(interactive()){
 labs <- list(x = list(class = "factor", `1` = "a", `2` = "b"))
 df <- data.frame(x = 1:2)
 data_label(df, value_labels = labs)
 }

## End(Not run)

worcs documentation built on Sept. 14, 2024, 5:06 p.m.