Learn R Programming

sjmisc (version 1.7)

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 adds value to the existing value labels of x.

Usage

add_labels(x, value)

add_labels(x) <- value

Arguments

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

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(`nothing` = 5))
get_labels(x)

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

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

# replace values, alternative function call
add_labels(x) <- c(`new second` = 2)

Run the code above in your browser using DataLab