labels: Get / Declare value labels

labelsR Documentation

Get / Declare value labels

Description

Functions to extract information about the declared variable / value labels, or to declare such values if they are present in the data.

Usage

label(x)

label(x, ...) <- value

labels(x) <- value

Arguments

x

Any vector of values that should be declared as missing (for labels) or a numeric vector of length two giving the (inclusive) extents of the range of missing values (for label).

...

Other arguments, for internal use.

value

The variable label, or a list of (named) variable labels

Details

The function labels() is a adaptation of the base function to the objects of class declared. In addition to the regular arguments, it has two additional (logical) arguments called prefixed (FALSE by default), to retrieve the value labels prefixed with their values, and print_as_df (TRUE by default) to print the result as a data frame.

Value

labels() will return a named vector.

label() will return a single character string.

See Also

Other labelling functions: drop_undeclare, measurement()

Examples

x <- declared(
    c(-2, 1:5, -1),
    labels = c("Good" = 1, "Bad" = 5, "DK" = -1),
    na_values = c(-1, -2),
    label = "Test variable"
)
x

labels(x)

labels(x, prefixed = TRUE)

labels(x) <- c("Good" = 1, "Bad" = 5, "DK" = -1, "Not applicable" = -2)

label(x)

label(x) <- "This is a proper label"

x


declared documentation built on May 29, 2024, 12:09 p.m.

Related to labels in declared...