Closed
Description
openedon Mar 26, 2021
According to the documentation, when the argument levels = "labels"
, then "unlabelled values become NA" which is ok.
However, when levels = "values"
I would have expected to obtain a factor having all values, labelled or not.
library(haven)
set.seed(1234)
x <- labelled(sample(1:5, 20, replace = TRUE), labels = c(Good = 1, Bad = 5))
as_factor(x, levels = "values")
# [1] <NA> <NA> 5 <NA> 1 5 <NA> <NA> <NA> <NA> <NA> <NA> 5 <NA> <NA> <NA>
# [17] 5 <NA> 5 <NA>
# Levels: 1 5
If the current functionality is alright, the documentation should mention it drops values without labels (just like the documentation for levels = "labels"
), or otherwise allow as_factor()
to use all values, which is what I would expect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
No labels