Search code examples
rrpart

Using rpart Package in R, error selecting all variables for decision tree model


I'm trying to create a decision tree model using a dataset with 200+ variables and I'm getting this error in using the . notation for all variables.

fit <- rpart(first_party ~ ., data=train)
Error in `[.data.frame`(m, labs) : undefined columns selected

The tree models fine when I define the variables by name, but I can't do that 200 times.

fit <- rpart(first_party ~ Crime + Number_of_Schools + Pop_Total, data=train)

Solution

  • It seemed to be the \ in one of the variable names.