The subset
methods must be called using no more than one of the
four main subsetting criteria arguments (tips.include
,
tips.exclude
, mrca
, or node.subtree
). Each of
these arguments can be either character or numeric. In the first case,
they are treated as node labels; in the second case, they are treated
as node numbers. For the first two arguments, any supplied tips not
found in the tree (tipLabels(x)
) will be ignored, with a
warning. Similarly, for the mrca
argument, any supplied tips
or internal nodes not found in the tree will be ignored, with a
warning. For the node.subtree
argument, failure to provide a
single, valid internal node will result in an error. Although prune
is mainly intended as the workhorse function
called by subset
, it may also be called directly. In general
it should be equivalent to the tips.exclude
form of
subset
(although perhaps with less up-front error checking).
The "[" operator, when used as x[i]
, is similar to the
tips.include
form of subset
. However, the indices used
with this operator can also be logical, in which case the
corresponding tips are assumed to be ordered as in nodeId(x,
"tip")
, and recycling rules will apply (just like with a vector or a
matrix). With a phylo4d object 'x', x[i,j]
creates a subset of x
taking i
for a tip index and
j
for the index of data variables in tdata(geospiza,
"all")
. Note that the second index is optional: x[i, TRUE]
,
x[i,]
, and x[i]
are all equivalent.
Regardless of which approach to subsetting is used, the argument
values must be such that at least two tips are retained.
If the most recent common ancestor of the retained tips is not the
original root node, then the root node of the subset tree will be a
descendant of the original root. For rooted trees with non-NA root
edge length, this has implications for the new root edge length. In
particular, the new length will be the summed edge length from the new
root node back to the original root (including the original root
edge). As an alternative, see the examples for a way to determine the
length of the edge that was immediately ancestral to the new root node
in the original tree.
Note that the correspondance between nodes and labels (and data in the
case of phylo4d) will be retained after all forms of
subsetting. Beware, however, that the node numbers (IDs) will likely
be altered to reflect the new tree topology, and therefore cannot be
compared directly between the original tree and the subset tree.