title: (How) can I extract the elements from the terminal nodes in a regression tree?
body: <p>I am quite new to R and I could not find an appropriate answer to my question, neither in the web nor in this forum. So I hope somebody can help me with clarification.
  I modelled some (simplified) regression trees with rpart<a href="https://i.stack.imgur.com/xJRn9.jpg" rel="nofollow noreferrer">example regression tree</a>, based on only 1 oder 2 predictors to analyse what connections are between them and the dependant variable. Here is the code I cosntructed after reading many threads and manuals. Maybe, it helps:</p>
  <pre><code>mydata &lt;- GWM_regression
  df &lt;- data.frame(mydata)
  set.seed(123)
  rows &lt;- sample(nrow(df))
  dfshuffle &lt;- df[rows, ]
  set.seed(123)
  dfshuffle03 &lt;- na.exclude(subset(dfshuffle))
  set.seed(123)
  sample &lt;- sample.int(n = nrow(dfshuffle03), size = floor(.9*nrow(dfshuffle03)), replace = F)
  dfshuffle03_train &lt;- dfshuffle03[sample, ]
  dfshuffle03_test  &lt;- dfshuffle03[-sample, ]
  set.seed(123)
  m3 &lt;- rpart (Detection_rate ~ DIF_2018, data = dfshuffle03_train, 
           method=&quot;anova&quot;, control = rpart.control(minsplit=20, cp=0, maxdepth=3))
  bestcp_m3 &lt;- m3$cptable[which.min(m3$cptable[,&quot;xerror&quot;]),&quot;CP&quot;]
  m3.pruned &lt;- prune(m3, cp = bestcp_m3)
  rpart.plot(m3.pruned, digits=3, extra=101, fallen.leaves=T, tweak=1, branch=1,
         varlen=-13)
  </code></pre>
  <p>The tree I got showed some terminal nodes, whose elements I would like to extract to plot them on a map. I used 90% of the data set for training purposes (maybe too much I know) so not alle elements of my original data are considered by the tree, but I need to know which ones are sorted in which subset.</p>
  <p>Is there any chance, to extract these data (as csv. oder txt.) from a regression tree model?</p>