Error while building a decision tree in R




While building a decision tree for a categorical variable in my dataset in R, I get an error when I try to plot my decision tree. The variable status_group is categorical and amount_tsh is numeric.

Error in apply(model$frame$yval2[, yval2per], 1, function(x) x[1 + x[1]]) :
dim(X) must have a positive length

Why is this error coming and how to remove it?



Hi @adityashrm21,

I faced the same problem. Did you updated your R software/ Rpart package. The problem is with Rgkt2 and I also didn’t find any fix for it.



I was facing a problem in installing the rattle package which gave some error related to Rgkt2. I use ubuntu and so googled for the error.
Then I used this result I found somewhere in the terminal

sudo apt-get install libgtk2.0-dev

which helped in installing the package and now I am not facing problem in installing any package. But then I got this error in decision tree. Now i don’t know again what to do for this.


Hi aditya,

I did the same, but the problem seems to be pertaining. Currently I can’t find any solution to it, still You can run R part, only problem is in plotting. You can still interpret the result and make a Tree for yourself, if the results are not convoluted.



Hey. Have you resolved the error? Me too facing the same problem.