Why is rpart not splitting this data even when there is gain in gini? df &lt;- tibble(x1=factor(c(&quot;S1&quot;, &quot;S1&quot;, &quot;S2&quot;, &quot;S2&quot;)), y=factor(c(1, 1, 0, 1)))
md &lt;- rpart(formula=y~., data=df, method=&quot;class&quot;, control=rpart.control(minsplit=2, cp=0))
nrow(md$frame) #outputs 1

consider the split
left child node :
&quot;S1&quot;, 1
&quot;S1&quot;, 1
right child node :
&quot;S2&quot;, 0
&quot;S2&quot;, 1
Here the gain in gini would be 1/8 = 0.125
why is rpart not doing this split?
It seems that rpart is actually using accuracy rather than gini in the cost complexity pruning, see e.g. https://stats.stackexchange.com/a/223211/232706
Since your split doesn't improve the misclassification rate, rpart doesn't make it even with cp=0.  Setting cp=-1, the split is performed.