Open fretwurst opened 5 months ago
Yes, I've gotten the same issue when working with multiple datasets. It looks like it's because when it's converted to factor by as_label()
, the levels of the factor are only the levels present in the variable.
In your example, using
factor(data$Answer)
leads to the same issue, but factor(data$Answer, levels = attr(data$Answer, "labels"))
has correct levels.
(And from there, factor(data$Answer, levels = attr(data$Answer, "labels"), labels = attr(attr(data$Answer, "labels"), "names"))
returns the correct labels, though I'm sure a more elegant solution exists.)
Thank you for your work! We work a lot with your packages.
For some reasons I found a label shift after some converting label, I had to do for graphics. The smallest possible value was not in the data (originally a student survey with no one under 18). After converting first to factor and afterwards zu label the label shiftet one step. Here is a reproducible example:
Is it a bug or a feature? :-)