Learn R Programming

sjmisc (version 2.0.1)

fill_labels: Add missing value labels to partially labelled vector

Description

This function adds value labels to a partially labelled vector, i.e. if not all values are labelled, non-labelled values get labels.

Usage

fill_labels(x)

Arguments

x
Variable (vector), data.frame or list of variables with partially added value labels (see labelled).

Value

x, where labels for non-labelled values are added.

See Also

drop_labels is the counterpart to fill_labels and drops labels from zero-count (non-existing) values.

Examples

Run this code
# create labelled integer, with tagged missings
library(haven)
x <- labelled(c(1:3, tagged_na("a", "c", "z"), 4:1),
              c("Agreement" = 1, "Disagreement" = 4, "First" = tagged_na("c"),
                "Refused" = tagged_na("a"), "Not home" = tagged_na("z")))
# get current values and labels
x
get_labels(x)

fill_labels(x)
get_labels(fill_labels(x))
# same as
get_labels(x, include.non.labelled = TRUE)

Run the code above in your browser using DataLab