What does rpart mean? Error in as.character (x): cannot force type "inline" to character vector "character"?

Iโ€™ve been knocking my head against it for several days rpart(trying to make classification trees for this data set that I have), and I think itโ€™s time to ask for a life buoy at this point :-) I'm sure this is something stupid that I donโ€™t see, but here is what I did:

EuropeWater <- read.csv(file=paste("/Users/artessaniccola/Documents/",
                       "Magic Briefcase/CityTypology/Europe_water.csv",sep=""))
library(rpart)
attach(EuropeWater)
names(EuropeWater)
[1] "City"          "waterpercapita_m3" "water_class"       "population"       
[5] "GDPpercapita"  "area_km2"          "populationdensity" "climate"            
EuropeWater$water_class <- factor(EuropeWater$water_class, levels=1:3, 
                                  labels=c("Low", "Medium", "High"))
EuropeWater$climate <- factor(EuropeWater$climate, levels=2:4, 
                              labels=c("Arid", "Warm temperate", "Snow"))
EuropeWater_tree <- rpart(EuropeWater$water_class ~ 
               population+GDPpercapita + area_km2 + populationdensity + 
               EuropeWater$climate, 
               data=EuropeWater, method=class)   
Error in as.character(x) : 
          cannot coerce type 'builtin' to vector of type 'character'

and for life I canโ€™t understand what a mistake is.

+3
source share
2 answers

It works?

EuropeWater_tree <- rpart(EuropeWater$water_class ~ 
 population+GDPpercapita + area_km2 + populationdensity + EuropeWater$climate, 
 data=EuropeWater, method="class")

I think you should indicate the type of method.

+16
source

: EuropeWater, data=:

res <- rpart(water_class ~ population + GDPpercapita + area_km2 + 
                           populationdensity + climate, 
             data=EuropeWater, method="class")

, , data.frame . , , csv, ? summary(EuropeWater) .

+3

Source: https://habr.com/ru/post/1734456/


All Articles