Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
as_factor returning labels with both numerical code and value labels #82
When working with labelled data, it's often very useful to have a feedback with both numerical code and value labels.
For example, I have a custom
In fact, seeing both numerical codes and value labels is useful when developing an analysis while for the final results we usually wants only the value labels.
PS: a more general question. It seems that several persons (@sjPlot for example) are starting to develop functions to deal with labelled variables. Do you have any plan to develop a dedicated package where such functions could be integrated?
Maybe something like this?
s1 <- labelled(c("M", "M", "F"), c(Male = "M", Female = "F")) as_factor(s1) as_factor(s1, labels = "values") #>  M M F #> Levels: M F as_factor(s1, labels = "labels") #>  Male Male Female #> Levels: Male Female as_factor(s1, labels = "labels") #>  [M] Male [M] Male [F] Female #> Levels: [M] Male, [F]Female
I guess he was asking for values that are associated with value labels. See for instance:
so you have
referenced this issue
Jul 3, 2015
Please let me know how the new
One thing I've realised is that factor levels containing spaces don't work particularly well with the default print method for factors:
as_factor(labelled(1:5, c(Bad = 1, Good = 5)), "both") #>   Bad 2 3 4  Good #> Levels:  Bad 2 3 4  Good
But it's not obvious if there's anything I can do here, except maybe suggest an enhancement to base R.