r - R:使用 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(...)
推荐阅读
- xml - Xpath 根据多个节点值过滤 xml
- youtube-api - 直播时如何让 youtube 广播自动启动?
- java - LIBGDX 平滑像素艺术渲染(这可能吗?)
- flutter - Dart Intl DateFormat.parse -1 年的差异,错误?
- acumatica - Can I dynamically set a PXDataFieldAssign parameter of a PXDataFieldParam object?
- r - R data.table 中缺少值的有效移位
- css - 如何解决我的 SharePointFramework 中的这个插件 sass 错误?
- docker - 如何让 --add-host 参数适用于 docker 构建?
- bash - Unix 脚本。如何在文件中搜索一个关键字,而另一个关键字删除整行?
- python - getattr 和 unicode 属性