我经常在库(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(...)