It seems that there is no function that allows you to extract observations from a specific node. I would solve this as follows: first determine which rule / s is used / used for the node you are installed into. You can use path.rpart for it. You can then apply the / s rule one by one to extract the observations.
This approach as a function:
get_node_date <- function(tree = fit, node = 5){ rule <- path.rpart(tree, node) rule_2 <- sapply(rule[[1]][-1], function(x) strsplit(x, '(?<=[><=])(?=[^><=])|(?<=[^><=])(?=[><=])', perl = TRUE)) ind <- apply(do.call(cbind, lapply(rule_2, function(x) eval(call(x[2], kyphosis[,x[1]], as.numeric(x[3]))))), 1, all) kyphosis[ind,] }
For node 5 you get:
get_node_date() node number: 5 root Start>=8.5 Start< 14.5 Kyphosis Age Number Start 2 absent 158 3 14 10 present 59 6 12 11 present 82 5 14 14 absent 1 4 12 18 absent 175 5 13 20 absent 27 4 9 23 present 96 3 12 26 absent 9 5 13 28 absent 100 3 14 32 absent 125 2 11 33 absent 130 5 13 35 absent 140 5 11 37 absent 1 3 9 39 absent 20 6 9 40 present 91 5 12 42 absent 35 3 13 46 present 139 3 10 48 absent 131 5 13 50 absent 177 2 14 51 absent 68 5 10 57 absent 2 3 13 59 absent 51 7 9 60 absent 102 3 13 66 absent 17 4 10 68 absent 159 4 13 69 absent 18 4 11 71 absent 158 5 14 72 absent 127 4 12 74 absent 206 4 10 77 present 157 3 13 78 absent 26 7 13 79 absent 120 2 13 81 absent 36 4 13
source share