ancestors.RdGet the ids of all ancestors of some taxa
ancestors(taxon_ids, taxo, n = Inf)
| taxon_ids | internal, numeric ids of the taxa. |
|---|---|
| taxo | a taxonomy data.frame, typically from |
| n | maximum number of levels to look up; n=1 gives the parents, n=2 gives the parents and the grand-parents, etc. |
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.
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.
Other taxonomy-related functions:
as.taxo(),
children(),
descendants(),
extract_taxo(),
is_leaf(),
lineage(),
parent(),
taxo_id(),
taxo_name()
#> levelName id #> 1 # NA #> 2 °--living 1 #> 3 ¦--fish 2 #> 4 ¦ °--egg 4 #> 5 °--mollusc 3 #> 6 ¦--snail 5 #> 7 ¦ °--egg 7 #> 8 °--squid 6ancestors(5, taxo)#> [1] 1 3 5ancestors(1, taxo)#> [1] 1ancestors(NA, taxo)#> [1] NAancestors(1:7, taxo)#> [1] 1 3 2 5 4 6 7ancestors(6, taxo, n=1)#> [1] 3 6ancestors(6, taxo, n=2)#> [1] 1 3 6ancestors(6, taxo, n=3)#> [1] 1 3 6ancestors(6, taxo, n=10)#> [1] 1 3 6# NB: ancestors(5:6, taxo, n=1)#> [1] 3 5 6#> [1] 3 3