Learn R Programming

sjmisc (version 1.2)

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

Examples

Run this code
# create labelled integer, with missing flag
x <- labelled(c(1, 2, 1, 3, 4, 1, 5),
              c(Good = 1, Bad = 5))
get_labels(x)
get_labels(x, include.non.labelled = TRUE)

fill_labels(x)
get_labels(fill_labels(x))

# create partially labelled vector with missings
x <- labelled(c(1, 2, 1, 3, 4, 1, 5),
              c(Male = 1, Female = 2, Refused = 5),
              c(FALSE, FALSE, TRUE))
x
fill_labels(x)
get_labels(fill_labels(x))

# get summary
x <- labelled(c(1, 2, 1, 3, 4, 1, NA, 5),
              c(Male = 1, Female = 2, Refused = 5),
              c(FALSE, FALSE, TRUE))
summary(x)

Run the code above in your browser using DataLab