我是编码新手,我正在尝试构建数据树,但我一直遇到同样的错误:
model.frame.default 中的错误(公式 = df ~ df$Open.Closed + df$Region,:变量“df”的类型(列表)无效
我浏览了整个网站,但无法找到解决我问题的有效方法。我尝试了多种解决方案,但我通常会遇到另一个错误,即数据是一个矩阵,该部分不会接受。任何帮助将非常感激。
这是我的代码:
library(rpart.plot)
library(ggExtra)
library(gridExtra)
library(RGtk2)
library(rpart)
library(rattle)
df[] <- data.frame(lapply(Test_Bank_Model,factor))
df [col_names] <- lapply(df[col_names], factor)
str(df)
summary(df)
print(df)
tree <- rpart(df ~ df$Open.Closed + df$Region, data = df, method = "class",
model = TRUE, control = rpart.control("minsplit" = 1))
rpart.plot(tree, roundint = FALSE, box.palette = "white")
Data:
Region
Closing.Date
Annual.Average.FedFunds
Open.Closed
1 South 2020 0.2328571 Closed
2 Mid West 2020 0.2328571 Closed
3 North East 2020 0.2328571 Open
4 South 2020 0.2328571 Open
5 North East 2020 0.2328571 Open
6 West 2020 0.2328571 Open
7 North East 2020 0.2328571 Open
8 North East 2019 1.7366667 Closed
9 South 2019 1.7366667 Closed
10 Mid West 2019 1.7366667 Closed