title: How to force rpart to do exactly 1 Split
body: <p>Having a problem similar to <a href="https://stackoverflow.com/questions/16135708/adabag-boosting-function-throws-error-when-giving-mfinal10">this</a>, I am trying to force rpart to do exactly one split. Here is a toy example that reproduces my problem:</p>
  
  <pre><code>require(rpart)
  
  y &lt;- factor(c(1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))
  x1 &lt;- c(12,18,15,10,10,10,20,6,7,34,7,11,10,22,4,19,10,8,13,6,7,47,6,15,7,7,21,7,8,10,15)
  x2 &lt;- c(318,356,341,189,308,236,290,635,550,287,261,472,282,262,1153,435,402,182,415,544,251,281,378,498,142,566,152,560,284,213,326)
  
  data &lt;- data.frame(y=y,x1=x1,x2=x2)
  tree &lt;-rpart(y~.,
                data=data,
                control=rpart.control(maxdepth=1, # at most 1 split
                                      cp=0, # any positive improvement will do
                                      minsplit=1,
                                      minbucket=1, # even leaves with 1 point are accepted
                                      xval=0)) # I don't need crossvalidation
  length(tree$frame$var) #==1, so there are no splits
  </code></pre>
  
  <p>Isolating a single point should be possible (minbucket=1) and even the most marginal improvement (isolating one point always decreases the misclassification rate) should lead to the split being kept (cp=0). </p>
  
  <p>Why does the result not include any splits? And how do I have to alter the code to always get exactly one split? Can it be that splits are not kept if both classify to the same factor output?</p>