
Last chance! 50% off unlimited learning
Sale ends in
Create a labelled
vector from an unlabelled
vector using lbl_relabel()
syntax, allowing for the grouping of multiple
values into a single label. Values not assigned a label remain unlabelled.
lbl_define(x, ...)
A labelled
vector
An unlabelled vector
Arbitrary number of two-sided formulas.
The left hand side should be a label placeholder created with lbl()
.
The right hand side should be a function taking .val
that
evaluates to TRUE
for all cases that should receive the label specified
on the left hand side.
Can be provided as an anonymous function or formula. See Details section.
Several lbl_*()
functions include arguments that can be passed a function
of .val
and/or .lbl
. These refer to the existing values and
labels in the input vector, respectively.
Use .val
to refer to the values in the vector's value labels.
Use .lbl
to refer to the label names in the vector's value labels.
Note that not all lbl_*()
functions support both of these arguments.
Other lbl_helpers:
lbl_add()
,
lbl_clean()
,
lbl_na_if()
,
lbl_relabel()
,
lbl()
,
zap_ipums_attributes()
age <- c(10, 12, 16, 18, 20, 22, 25, 27)
# Group age values into two label groups.
# Values not captured by the right hand side functions remain unlabelled
lbl_define(
age,
lbl(1, "Pre-college age") ~ .val < 18,
lbl(2, "College age") ~ .val >= 18 & .val <= 22
)
Run the code above in your browser using DataLab