决策树的“不能对不存在的列进行子集化”
'Can't subset columns that don't exist' for decision trees
你好,我正在用 R 编写决策树,当我 运行 我的代码时出现这个错误:
错误:无法对不存在的列进行子集化。
x 列 Member
、Normal
、Normal
、Member
、Normal
等不存在。
df 是一个数据框。你能帮我吗 ?谢谢你。这是我的代码:
library(rpart)
library(caret)
library(dplyr)
library(rpart.plot)
library(xlsx)
library(caTools)
library(data.tree)
library(elemstatlearn)
#Loading Excel File
library(readxl)
FINALDATA <- read_excel("Desktop/FINALDATA.xlsm")
View(FINALDATA)
df <- FINALDATA
View(df)
#Selecting the meaningful columns for prediction
df <- select(df, City, df$`Customer type`, df$Gender, df$Quantity, df$Total, df$Date, df$Time, df$Payment, df$Rating)```
dplyr::select
的正确用法是引用或不引用列名,而不是该列的值(df$City
- 提取该列的值)
library(dplyr)
df1 <- select(df, City, `Customer type`, Gender,
Quantity, Total, Date, Time, Payment, Rating)
此外,还有许多 select-helpers
可用(starts_with
、ends_with
、matches
)或使用范围,即如果我们有兴趣从城市中选择所有列要评分,请使用 :
df1 <- select(df, City:Rating)
你好,我正在用 R 编写决策树,当我 运行 我的代码时出现这个错误:
错误:无法对不存在的列进行子集化。
x 列 Member
、Normal
、Normal
、Member
、Normal
等不存在。
df 是一个数据框。你能帮我吗 ?谢谢你。这是我的代码:
library(rpart)
library(caret)
library(dplyr)
library(rpart.plot)
library(xlsx)
library(caTools)
library(data.tree)
library(elemstatlearn)
#Loading Excel File
library(readxl)
FINALDATA <- read_excel("Desktop/FINALDATA.xlsm")
View(FINALDATA)
df <- FINALDATA
View(df)
#Selecting the meaningful columns for prediction
df <- select(df, City, df$`Customer type`, df$Gender, df$Quantity, df$Total, df$Date, df$Time, df$Payment, df$Rating)```
dplyr::select
的正确用法是引用或不引用列名,而不是该列的值(df$City
- 提取该列的值)
library(dplyr)
df1 <- select(df, City, `Customer type`, Gender,
Quantity, Total, Date, Time, Payment, Rating)
此外,还有许多 select-helpers
可用(starts_with
、ends_with
、matches
)或使用范围,即如果我们有兴趣从城市中选择所有列要评分,请使用 :
df1 <- select(df, City:Rating)