add_labels() adds labels for selected variables such as sex, cancer, and areacode in the dataset based on the specified language and label type.

add_labels(
  x,
  vars = c("sex", "cancer", "areacode"),
  label_type = "full",
  lang = "zh",
  as_factor = TRUE
)

Arguments

x

A data frame or tibble to be labeled.

vars

A character vector of variable names to label. Default includes "sex", "cancer", and "areacode".

label_type

Type of the label used ("full" or "abbr").

lang

Character, specify the output language, options are 'cn', or 'en', default is 'cn'.

as_factor

Logical, indicate whether output value as factor.

Value

A data frame or tibble with labeled variables and reordered columns.

Examples

data("canregs")
asr <- create_asr(canregs[[1]], year, sex, cancer)
asr <- add_labels(asr, label_type = "full", lang = "zh")
asr <- add_labels(asr, label_type = "full", lang = "en")