On the right hand side is the current order of the categorical variable
我正在尝试更改顺序,因此“Charged Off”和“Default”位于底部,而其余部分保持不变。我似乎无法重新订购或重新开始工作。大多数时候我都会收到错误
Error: unexpected string constant in "post09$LoanStatus <- relevel(post09$LoanStatus, ref = c("Cancelled", Completed", ""
答案 0 :(得分:0)
试试这个并告诉我它是否有效 -
data <- factor(letters[1:10])
data1 <- c("i","j",setdiff(data,c("i","j")))
data_reordered <- factor(data1, levels=data1)
如果没有,请分享有关您的问题的更多信息以及可重现的示例!
答案 1 :(得分:0)
我已经假设水平必须已经是因素,但事实证明你可以拥有水平而不是一个因素。
我只是使用
修复它post09$LoanStatus <- factor(post09$LoanStatus, levels = c("Completed", "FinalPaymentInProgress", "Current", "Past Due (1-15 days)", "Past Due (16-30 days)", "Past Due (31-60 days)", "Past Due (61-90 days)", "Past Due (91-120 days)", "Past Due (>120 days)", "Chargedoff", "Defaulted"))