如何在R中将变量'labeled'的类更改为string或chr?

问题描述 投票:3回答:1

如何将“标记”类的变量更改为仅将标签显示为字符串或字符的字符变量?所以我只想查看最后一个属性,请参阅下面的变量结构。

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" ...
r functional-programming char label
1个回答
3
投票

我有同样的问题,找不到指定的功能。

转换为因子然后字符应该工作,但是:

s2 <- labelled(c(1, 1, 2), c(Male = 1, Female = 2)) # example from haven:labelled
as.character(as_factor(s2)) # use haven::as_factor
© www.soinside.com 2019 - 2024. All rights reserved.