
Last chance! 50% off unlimited learning
Sale ends in
"prune"
takes an object of class "dendrogram"
and
removes all branches whose branch labels match a given regular
expression.
prune(tree, pattern, invert = FALSE, untag = FALSE, ...)
an object of class "dendrogram"
.
a regular expression.
logical indicating whether the branches whose labels match the regular expression provided in "pattern" should be discarded and the others kept (FALSE; default) or vice versa. Nodes without "label" attributes are ignored.
logical (used only when invert = TRUE). Indicates whether the specified pattern should be removed from the branch labels in the returned object.
further arguments to be passed to grepl
and gsub
.
Returns an object of class "dendrogram"
.
This function recursively tests the "label" attribute of each dendrogram node (including non-leaf inner nodes if applicable) for the specified pattern, removing those that register a positive hit. Note that positive matching inner nodes are removed along with all of their sub-nodes, regardless of whether the "label" attributes of the sub-nodes match the pattern.
The drop.tip
function in the
ape
package performs a similar operation for objects
of class "phylo"
. See regex
for help with
compiling regular expressions.
# NOT RUN {
x <- read.dendrogram(text = "(A:0.1,B:0.2,(C:0.3,D:0.4):0.5);")
plot(x, horiz = TRUE)
x <- prune(x, pattern = "^A$")
plot(x, horiz = TRUE)
# }
Run the code above in your browser using DataLab