rpart.predict.leaves: Return the leaf into which observations are predicted to fall

Description Usage Arguments Details Value Author(s) See Also


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


Search within the treeClust package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.