R/phy_OtuMetaTable.R

Defines functions phy_OtuMetaTable

Documented in phy_OtuMetaTable

#' merge otu and metadata table
#'
#' @param physeq a phyloseq object with otu and metadata tables available
#'
#' @return a data.frame object, with otus as first columns, and metadata merged after them
#' @export
#'
#' @examples
#'
#' data(GlobalPatterns)
#'
#' otuMeta <- OtuMetaTable(GlobalPatterns)

phy_OtuMetaTable <- function(physeq){
  otu <- t(microbiome::abundances(physeq)) %>%
    as.data.frame() %>%
    rownames_to_column("sampIDs")

  meta <- microbiome::meta(physeq) %>%
    rownames_to_column("sampIDs")

  otuMeta <- merge(otu, meta, by = "sampIDs", sort = FALSE)

  return(otuMeta)
}
g-antonello/gautils2 documentation built on Nov. 28, 2022, 9:39 a.m.