Learn R Programming

sjmisc (version 1.2)

labelled: Create a labelled vector

Description

A labelled vector is a common data structure in other statistical environments.

Usage

labelled(x, labels, is_na = NULL)

Arguments

x
Vector to label. Must be either numeric or character.
labels
Named vector. The vector should be the same type as x. Unlike factors, labels don't need to be exhaustive: only a fraction of the values might be labelled.
is_na
Optionally, logical vector describing which levels should be translated to missing values

Examples

Run this code
# labelled vector with multiple types of missing values
x <- labelled(c("M", "M", "F", "X", "N/A"),
              c(Male = "M", Female = "F", Refused = "X", "Not applicable" = "N/A"),
              c(FALSE, FALSE, TRUE, TRUE))

Run the code above in your browser using DataLab