我试图确保在我的树对象和用于预测的测试集中,我的类型因子的所有特征都被完全表示(就所有可能的因子水平而言)。
for (j in 1:length(predictors)){
if (is.factor(Test[,j])){
ct [[names(predictors)[j]]] <- union(ct$xlevels[[names(predictors)[j]]], levels(Test[,c(names(predictors)[j])]))
}
}
但是,对于对象 ct(来自包方的 ctree),我似乎无法理解如何访问功能的因子级别,因为我遇到了错误
Error in ct$xlevels : $ operator not defined for this S4 class