Using the information in the data dictionary, this function adds non-missing information from the data dictionary as attributes to the data.
Arguments
- DD.dict
Data dictionary.
- DS.data
Data set.
- non.NA.missing.codes
A user-defined vector of numerical missing value codes (e.g., -9999).
Value
A tibble containing the labelled data set, with the data dictionary information embedded as attributes and variables labelled using Haven SPSS conventions.
Examples
data(ExampleB)
DS_labelled_data <- label_data(DD.dict.B, DS.data.B, non.NA.missing.codes=c(-9999))
labelled::var_label(DS_labelled_data$SEX)
#> [1] "Sex assigned at birth"
labelled::val_labels(DS_labelled_data$SEX)
#> male female
#> 0 1
attributes(DS_labelled_data$SEX)
#> $labels
#> male female
#> 0 1
#>
#> $label
#> [1] "Sex assigned at birth"
#>
#> $class
#> [1] "haven_labelled" "vctrs_vctr" "integer"
#>
#> $TYPE
#> [1] "integer, encoded value"
#>
#> $MIN
#> [1] 0
#>
#> $MAX
#> [1] 1
#>
labelled::na_values(DS_labelled_data$HX_DEPRESSION)
#> missing value
#> -9999