R/path.itree.R

Defines functions path.itree

Documented in path.itree

#ALG: itree copies this direclty from rpart.
# submitted by Anantha Prasad 1/26/98

path.itree <- function(tree, nodes, pretty = 0, print.it = TRUE)
{
        if(!inherits(tree, "itree"))
                stop("Not legitimate itree object")
        splits <- labels.itree(tree, pretty = pretty) #switched to itree
        frame <- tree$frame
        n <- row.names(frame)
        node <- as.numeric(n)
        which <- descendants(node)      #ancestors are columns
        path <- list()
        if(missing(nodes)) {
                xy <- rpartco(tree)
                while(length(i <- identify(xy, n = 1L, plot = FALSE)) > 0L) {
                        path[[n[i]]] <- path.i <- splits[which[, i]]
                        if(print.it) {
                                cat("\n", "node number:", n[i], "\n")
                                cat(paste("  ", path.i), sep = "\n")
                        }
                }
        }
        else {

                if(length(nodes <- node.match(nodes, node)) == 0L)
                        return(invisible())
                for(i in nodes)
                       { path[[n[i]]] <- path.i <- splits[which[, i]]
			if(print.it) {
                                cat("\n", "node number:", n[i], "\n")
                                cat(paste("  ", path.i), sep = "\n")
                                }
                       }
        }
        invisible(path)
}

Try the itree package in your browser

Any scripts or data that you put into this service are public.

itree documentation built on May 2, 2019, 7:25 a.m.