gpt4 book ai didi

R:使用 car::recode 函数重新编码变量时出错

转载 作者:行者123 更新时间:2023-12-04 02:58:55 35 4
gpt4 key购买 nike

我经常在 library(car) 中使用“重新编码”函数来重新编码变量中的级别。直到今天,我的代码都运行良好,但现在却出现了错误。
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

最佳答案

它对我来说在一个干净的 session 中工作。我猜 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(...)

关于R:使用 car::recode 函数重新编码变量时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51066938/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com