View source: R/labelled_to_factor.R
labelled_to_factor | R Documentation |
Convert labelled numerics to factors
labelled_to_factor(x)
x |
an atomic numeric with the attribute "labels". Probably from |
a factor
This is a bit of a quirky solution because the integers underlying a factor are default set to 1 through the number of unique items. This means that without saving the original value labels
Sven Halvorson (svenpubmail@gmail.com)
city_labels = c(
'Urruk' = 2,
'Babylon' = 3,
'Larsa' = 4,
'Mari' = 5
)
set.seed(0)
cities = sample(2:5, size = 10, replace = TRUE)
expss::val_lab(cities) = city_labels
labelled_to_factor(cities)
# NOTE the difference:
as.numeric(labelled_to_factor(cities)) == cities
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.