lbl_define | R Documentation |
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, ...)
x |
An unlabelled vector |
... |
Arbitrary number of two-sided formulas. The left hand side should be a label placeholder created with The right hand side should be a function taking 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.
A labelled
vector
Other lbl_helpers:
lbl()
,
lbl_add()
,
lbl_clean()
,
lbl_na_if()
,
lbl_relabel()
,
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
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.