Return the leaf into which observations are predicted to fall


The "where" element of an rpart object gives the leaf into which each observation used building the tree falls. This produces the equivalent for new data.


rpart.predict.leaves(rp, newdata, type = "where")



Object of class rpart.


New data frame, with the columns used in the rpart model.


Style of leaf identification: "where" or "leaf"


There are two ways to identify the leaf into which an observation falls. The way used in the "where" element of an rpart object is to give the row number of the leaf within the object's "frame" element. That is the approach used here when type = "where". When type = "leaf" the actual leaf number is returned. For example, in a tree where node 2 is a terminal node and node 3 splits into terminal nodes 6 and 7, type = "leaf" will return a vector with values 2, 6 and 7. Type = "where" will return a vector with values 2, 4 and 5, since rows 2, 4 and 5 of the tree's "frame" element are leaves.


If type = "where", numeric vector of row numbers describing leaves in the tree's "frame" component. If type = "leaf," character vector of leaf numbers.


Sam Buttrey

See Also


Want to suggest features or report bugs for Use the GitHub issue tracker. Vote for new features on Trello.

comments powered by Disqus