练习R:car包recode函数多分类变量的重新编码

01
基本语法
x为数值向量,字符向量或者factor 变量。
recode为设定重新编码规则的字符串。
as.factor.result为是否输出factor变量。若是则为TRUE,不是为FALSE。
levels为排序向量。指定新的编码分组的顺序(默认是按照分组名称排序)。
02
编码规则写法
03
具体案例写法
employee$educ <- recode(
employee$educ,
"8='1';
12='2';
c(14,15,16)='3';
else='4'",
as.factor = T,
levels = c("1","2","3","4")
)


赞 (0)