Error in 1:numclass : result would be too long a vector in R

r

#1

Hi,

I was trying to build a decision tree model on a dataset using the rpart library.

library(rpart)
mod<-rpart(Category~.,data=train_data,method=“class”)

and I get an error saying

Error in 1:numclass : result would be too long a vector

How to handle this error?

thank you.


#2

see this

Factors are ideal for categorical variables These are continuous variables. Decision tree will create dummy variables for anything you pass as factors. In this case the are probably hundred unique values for Plength, Pwidth etc. that’s why you are seeing this error.