Functions to extract information about the declared variable / value labels, or to declare such values if they are present in the data.
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 (forlabel).- ...
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 an
additional logical one called prefixed, to retrieve the value labels
prefixed with their values.
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
#> <declared<integer>[7]> Test variable
#> [1] NA(-2) 1 2 3 4 5 NA(-1)
#> Missing values: -1, -2
#>
#> Labels:
#> value label
#> 1 Good
#> 5 Bad
#> -1 DK
labels(x)
#> Good Bad DK
#> 1 5 -1
labels(x, prefixed = TRUE)
#> [1] Good [5] Bad [-1] DK
#> 1 5 -1
labels(x) <- c("Good" = 1, "Bad" = 5, "DK" = -1, "Not applicable" = -2)
label(x)
#> [1] "Test variable"
label(x) <- "This is a proper label"
x
#> <declared<integer>[7]> This is a proper label
#> [1] NA(-2) 1 2 3 4 5 NA(-1)
#> Missing values: -1, -2
#>
#> Labels:
#> value label
#> 1 Good
#> 5 Bad
#> -1 DK
#> -2 Not applicable