重新编码一个 hevan_labelled 变量
Recoding one hevan_labelled variable
我试图重新编码复杂调查数据集的一个变量。
我试过 dplyr::recode 功能。
occup<-recode(sv$v717, c(0 )='0'; c(1, 2, 3 )='1'; c(4 )='2'; c(8, 9 )='3'; c(96, 98)='98'")
之前我也是用同样的方法成功的。
但是,这次我收到如下错误
Error in UseMethod("recode") : no applicable method for 'recode' applied to an object of class "c('haven_labelled', 'vctrs_vctr', 'double')"
如何修复此错误或如何重新编码变量?
我找到了解决方案
occu<-car::recode(sv$v717, "c(0 )=0; c(1, 2, 3 )=1; c(4 )=2; c(8, 9 )=3; c(96, 98)=98")
Car包的recode功能可以解决这个问题
我试图重新编码复杂调查数据集的一个变量。 我试过 dplyr::recode 功能。
occup<-recode(sv$v717, c(0 )='0'; c(1, 2, 3 )='1'; c(4 )='2'; c(8, 9 )='3'; c(96, 98)='98'")
之前我也是用同样的方法成功的。 但是,这次我收到如下错误
Error in UseMethod("recode") : no applicable method for 'recode' applied to an object of class "c('haven_labelled', 'vctrs_vctr', 'double')"
如何修复此错误或如何重新编码变量?
我找到了解决方案
occu<-car::recode(sv$v717, "c(0 )=0; c(1, 2, 3 )=1; c(4 )=2; c(8, 9 )=3; c(96, 98)=98")
Car包的recode功能可以解决这个问题