How do I change the class of a variable "marked" to string or chr in R?

How can I change a class variable tagged into a character variable only displaying the tags as a string or character? So I only want to see the last attribute, see below for my variable structure.

Class 'labelled'  atomic [1:918] 4 12 13 20 26 36 40 1 4 13 ...
..- attr(*, "format.spss")= chr "F8.0"
..- attr(*, "labels")= Named num [1:40] 1 2 3 4 5 6 7 8 9 10 ...
.. ..- attr(*, "names")= chr [1:40] "People management" "HR" "Self management" "Email" ...

      

+3


source to share


1 answer


I had the same question and couldn't find the assigned function.

The conversion to coefficient should then work, however:



s2 <- labelled(c(1, 1, 2), c(Male = 1, Female = 2)) # example from haven:labelled
as.character(as_factor(s2)) # use haven::as_factor

      

+2


source







All Articles