Learn R Programming

sjmisc (version 1.2)

add_labels: Add value labels to variables

Description

This function adds additional labels as attribute to a variable or vector x, resp. to a set of variables in a data.frame or list-object. Unlike set_labels, add_labels does not replace existing value labels, but add labels to the existing value labels of x.

Usage

add_labels(x, labels)

Arguments

x
Variable (vector), list of variables or a data.frame where value label attributes should be added. Does not replaces former value labels.
labels
Named character vector of labels that will be added to x as "labels" or "value.labels" attribute. If x is a data frame, labels may also be a

Value

  • x with additional value labels.

See Also

set_label to manually set variable labels or get_label to get variable labels; set_labels to add value labels, replacing the existing ones.

Examples

Run this code
data(efc)
get_labels(efc$e42dep)

x <- add_labels(efc$e42dep, c(`5` = "nothing"))
get_labels(x)

x <- add_labels(efc$e42dep, c(`5` = "nothing", `0` = "zero value"))
get_labels(x, include.values = "p")

# replace old values
x <- add_labels(efc$e42dep, c(`4` = "not so dependent", `5` = "lorem ipsum"))
get_labels(x, include.values = "p")

Run the code above in your browser using DataLab