Skip to contents

Use the data labels of a variable instead of its values [Experimental]

Usage

use_labels(tbl, dict, vars = NULL, ignore_case = F, check = TRUE)

Arguments

tbl

data.frame: Data.frame with the data

dict

data.frame: Dictionary with all the data labels to use if they have not yet been assigned. See Details

vars

character: If specified, only labels are assigned to those variables

ignore_case

logical: Indicate if case sensitive should be ignored

check

logical: If TRUE (default), the function will check if values present in variable are valid data labels in dictionary.

Value

The data supplied in the tbl argument, but instead of values using the corresponding data labels

Details

This function assumes that the data labels have been assigned to the data before, unless a dict is supplied, in which case the latter will be used to assign and use the data labels.

Examples

if (FALSE) {
dict <- list(
  SEX = list(
    lab = "Sex of the person",
    labs = c(
      "Man" = 1,
      "Woman" = 2
    )
  )
)
enft <- data.frame(SEX = c(1, 2))
enft
use_labels(enft, dict = dict)
}