Creates a labelled
vector from an unlabelled atomic
vector using lbl_relabel
syntax, which allows grouping multiple
values into a single labelled value. Values not assigned a label will remain
unlabelled.
lbl_define(x, ...)
x | An unlabelled atomic vector |
---|---|
... | Two-sided formulas where the left hand side is a label placeholder
(created with the |
A haven::labelled vector
Other lbl_helpers:
lbl_add()
,
lbl_clean()
,
lbl_collapse()
,
lbl_na_if()
,
lbl_relabel()
,
lbl()
,
zap_ipums_attributes()
age <- c(10, 12, 16, 18, 20, 22, 25, 27) # Note that values not assigned a new labelled value remain unchanged lbl_define( age, lbl(1, "Pre-college age") ~ .val < 18, lbl(2, "College age") ~ .val >= 18 & .val <= 22 ) #> <labelled<double>[8]> #> [1] 1 1 1 2 2 2 25 27 #> #> Labels: #> value label #> 1 Pre-college age #> 2 College age