set_labels {hesim} | R Documentation |
Set value labels
Description
Update existing variables or create new ones that replace existing values
with more informative labels as in factor()
. All modifications are performed
by reference (see data.table::set()
for more information about assignment by
reference).
Usage
set_labels(x, labels, new_names = NULL, as_factor = TRUE)
Arguments
x |
A |
labels |
A list of named vectors containing the values and labels of
variables. The elements of each vector are the values of a variable and the
names are the labels. The names of the list are the names of the variables.
See the output returned by |
new_names |
A character vector of the same length as |
as_factor |
If |
Value
x
is modified by reference and returned invisibly.
See Also
Examples
library("data.table")
labs <- list("strategy_id" = c("s1" = 1,
"s2" = 2),
"grp_id" = c("g1" = 1,
"g2" = 2))
d1 <- data.table(strategy_id = 1:2, grp_id = 1:2)
d2 <- copy(d1); d3 <- copy(d2)
set_labels(d2, labels = labs)
set_labels(d3, labels = labs, new_names = c("strategy_name", "grp_name"))
d1
d2
d3