[英]R: Error while recoding variables using car::recode function
我经常在library(car)中使用“ recode”功能来重新编码变量中的级别。 直到今天,我的代码都可以正常工作,但是现在却使我出错。 df等没有任何变化,不确定发生了什么。
也许有人可以启发我!
我的数据框(样本) :
test<-structure(list(Avg.Salary = c("65000", "395", "82000", "128357",
"95785", "95785"), Education = c("Doctorate", "Professional Degree",
"Bachelor's", "Professional Degree", "Master's", "Master's"),
Count = c("D", "D", "D", "D", "D", "364584"), Year = c(2017,
2017, 2017, 2017, 2017, 2017)), row.names = c("540061", "540071",
"540081", "540091", "540102", "540112"), class = "data.frame")
我实际数据集中的水平 :-
Associate Degree Associates Bachelor's
205 35 42446
D Doctorate High School
42902 9846 191
Master's Missing Education No Diploma
57644 218 79
Professional Professional Degree Some College
431 6791 60
Some College Credits
370
我的代码(到今天为止还不错!) :-
# Recode the education levels
test$Education<-recode(test$Education,
"c('Associate Degree','Associates','D','High School',
'No Diploma','Missing Education',
'Professional','Professional Degree','Some College',
'Some College Credits')='Others'")
错误 :- Error: Argument 2 must be named, not unnamed
它对我来说是一个干净的会议。 我猜car::recode()
与dplyr::recode()
有冲突。 合格功能是否起作用? 将recode
替换为car::recode
。
test$Education <- car::recode(test$Education,
"c('Associate Degree','Associates','D','High School',
'No Diploma','Missing Education',
'Professional','Professional Degree','Some College',
'Some College Credits')='Others'")
当我显式调用dplyr::recode()
,出现错误“错误:参数2必须命名,而不是未命名”。
test$Education <- dplyr::recode(...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.