title: How to climb the tree structure of rpart object using path in order to purge manually some nodes?
body: <p>I am using rpart for building a classification tree. I want to develop my own pruning function based on some criteria on the leaf nodes. 
  For instance, if one leaf node is not good regardind to some criteria (stability of parameters' estimation in my case) I want to climb in the tree structure and get the parent node of this leaf node (even if this node is not terminal). 
  For this, I want to traverse the tree using path and I need to get the leaf nodes with their parents nodes, in order to climb the tree if necessary.</p>
  
  <p>Let's look at this example : </p>
  
  <pre><code>fit &lt;- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis)
  
  &gt; fit
  n= 81 
  
  node), split, n, loss, yval, (yprob)
   * denotes terminal node
  
  1) root 81 17 absent (0.79012346 0.20987654) 
  2) Start&gt;=8.5 62 6 absent (0.90322581 0.09677419) 
  4) Start&gt;=14.5 29 0 absent (1.00000000 0.00000000) *
  5) Start&lt; 14.5 33 6 absent (0.81818182 0.18181818) 
  10) Age&lt; 55 12 0 absent (1.00000000 0.00000000) *
  11) Age&gt;=55 21 6 absent (0.71428571 0.28571429) 
  22) Age&gt;=111 14 2 absent (0.85714286 0.14285714) *
  23) Age&lt; 111 7 3 present (0.42857143 0.57142857) *
  3) Start&lt; 8.5 19 8 present (0.42105263 0.57894737) *
  </code></pre>
  
  <p>With fit$frame I can get the information about leaf nodes :</p>
  
  <pre><code>fit$frame 
  
  var n wt dev yval complexity ncompete nsurrogate yval2.V1 yval2.V2 yval2.V3 yval2.V4 yval2.V5
  1 Start 81 81 17 1 0.17647059 2 1 1.00000000 64.00000000 17.00000000 0.79012346 0.20987654
  2 Start 62 62 6 1 0.01960784 2 2 1.00000000 56.00000000 6.00000000 0.90322581 0.09677419
  4 &lt;leaf&gt; 29 29 0 1 0.01000000 0 0 1.00000000 29.00000000 0.00000000 1.00000000 0.00000000
  5 Age 33 33 6 1 0.01960784 2 2 1.00000000 27.00000000 6.00000000 0.81818182 0.18181818
  10 &lt;leaf&gt; 12 12 0 1 0.01000000 0 0 1.00000000 12.00000000 0.00000000 1.00000000 0.00000000
  11 Age 21 21 6 1 0.01960784 2 0 1.00000000 15.00000000 6.00000000 0.71428571 0.28571429
  22 &lt;leaf&gt; 14 14 2 1 0.01000000 0 0 1.00000000 12.00000000 2.00000000 0.85714286 0.14285714
  23 &lt;leaf&gt; 7 7 3 2 0.01000000 0 0 2.00000000 3.00000000 4.00000000 0.42857143 0.57142857
  3 &lt;leaf&gt; 19 19 8 2 0.01000000 0 0 2.00000000 8.00000000 11.00000000 0.42105263 0.57894737
  </code></pre>
  
  <p>I can get the correspondance of the rows in the data table with the corresponding leaf node it falls in using : fit$where</p>
  
  <p>Now I want to get also the parents of a leaf node. I know that path.rpart gives me all the splits done in order to obtain the leaf node. For example for leaf node 23:</p>
  
  <pre><code>&gt; path.rpart(fit, 23)
  
  node number: 23 
   root
   Start&gt;=8.5
   Start&lt; 14.5
   Age&gt;=55
   Age&lt; 111
  </code></pre>
  
  <p>What I want to obtain is a path with the node numbers of the parents of node 23? How can I do this association?</p>
  
  <p>Thank you in advance.</p>