R/dominant.R

Defines functions dominant

Documented in dominant

#' @title Dominant taxa
#' @description Returns the dominant taxonomic group for each sample.
#' @param x A \code{\link{phyloseq-class}} object
#' @param level Optional. Taxonomic level.
#' @return A vector of dominance indices
#' @export
#' @examples
#' data(dietswap)
#' # vector
#' d <- dominant(dietswap)
#' @author Leo Lahti \email{microbiome-admin@@googlegroups.com}
#' @keywords utilities
dominant <- function(x, level = NULL) {

    if (!is.null(level)) {
        x <- aggregate_taxa(x, level = level)
    }

    # TODO add support to other taxonomic levels
    taxa(x)[apply(abundances(x), 2, which.max)]

}

Try the microbiome package in your browser

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

microbiome documentation built on Nov. 8, 2020, 5:08 p.m.