ancestors: Get the ids of all ancestors of some taxa

View source: R/taxo.R

ancestorsR Documentation

Get the ids of all ancestors of some taxa

Description

Get the ids of all ancestors of some taxa

Usage

ancestors(taxon_ids, taxo, n = Inf)

Arguments

taxon_ids

internal, numeric ids of the taxa.

taxo

a taxonomy data.frame, typically from extract_taxo().

n

maximum number of levels to look up; n=1 gives the parents, n=2 gives the parents and the grand-parents, etc.

Details

Even with n=1, the function is different from parent() because it returns all unique parents for all elements of taxon_ids, not one parent per element.

Value

A vector of taxonomic ids containing the input taxon_ids and all their ancestors. With a single taxon in taxon_ids, the ancestors are in ordered from the taxon to the root of the tree: they define the lineage. When taxon_ids contains multiple taxa, the order is non-trivial.

See Also

Other taxonomy-related functions: as.taxo(), children(), descendants(), extract_taxo(), is_leaf(), lineage(), parent(), taxo_id(), taxo_name()

Examples

print(as.Node(taxo), "id")
ancestors(5, taxo)
ancestors(1, taxo)
ancestors(NA, taxo)
ancestors(1:7, taxo)
ancestors(6, taxo, n=1)
ancestors(6, taxo, n=2)
ancestors(6, taxo, n=3)
ancestors(6, taxo, n=10)
# NB:
ancestors(5:6, taxo, n=1)
parent(5:6, taxo)

jiho/ecotaxar documentation built on Jan. 16, 2024, 12:26 a.m.