Skip to contents

Replace category codes with their labels.

Usage

z22_decode(codes, feature, year = NULL, lang = c("english", "german"))

Arguments

codes

A vector of character codes, possibly prefixed with "cat_".

feature

A grid feature that the category codes belong to.

year

Census year. This is needed only for four features, birth_country, citizenship_group, dwelling_constr_year, and building_constr_year. These features rely on categories that changed between census years. For other features, this argument is ignored.

lang

Specifies the language of the output description. Can be either "english" (default) or "german". Note that the English descriptions are only ad-hoc translations based off the German originals.

Value

.data with category codes decoded to labels.

Examples

# retrieves a the translation of cat codes directly
z22_decode(1, "marital_status")
#> [1] "Single"

# recycles codes
z22_decode(c(1, 1, 1), "marital_status")
#> [1] "Single" "Single" "Single"

# undefined codes are returned as NA
z22_decode(c(1, 2, 3), feature = "sex")
#> [1] "Male"   "Female" NA      

# special case: cat_* strings
z22_decode("cat_2", feature = "sex")
#> [1] "Female"