[R] rpart error when constructing a classification tree

Randy Griffiths rgriff77 at gmail.com
Thu Jan 31 06:50:42 CET 2008


I am trying to make a decision tree using rpart. This is my code and output.
> data <- read.table("/Users/randygriffiths/Desktop/data", header=T)
> attach(data)
>
> library(rpart)
> bookings.cart <- rpart(totalRev~., data=data, method="class")
> bookings.cart
n= 50

node), split, n, loss, yval, (yprob)
      * denotes terminal node

1) root 50 15 0 (0.7 0.04 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02
0.02 0.02 0.02) *
> summary(bookings.cart)
Call:
rpart(formula = totalRev ~ ., data = data, method = "class")
  n= 50

  CP nsplit rel error
1  0      0         1
Error in yval[, 1] : incorrect number of dimensions


I have used rpart on past projects without any problems. I can do a
regression tree without any error as well (by leaving off the method="class"
argument). I have used this same data using 'randomForest' with good results
and also using 'tree' without this error. I have seen that at least a few
people have reported getting this same error with rpart, but I could not
find an answer that helped the problem. Can anyone help me?

Randy


More information about the R-help mailing list