add_metadata: Add metadata to data.frame

View source: R/add_metadata.R

add_metadataR Documentation

Add metadata to data.frame

Description

This function combines two tables based on the row identifiers.

Usage

add_metadata(x, metad, xid = NULL, mid = NULL, drop_mid = T)

Arguments

x

Data frame with data of interest

metad

Data frame with metadata that should be added; or phyloseq object with sample_data slot

xid

Character, name of the column with row identifiers in the main data (x)

mid

Character, name of the column with row identifiers in the metadata (metad)

drop_mid

Logical; if TRUE (default), metadata identifiers will be removed from results

Value

Data frame

Examples

# Load data
data(GlobalPatterns)

# As an example, estimate richness
div <- estimate_richness(GlobalPatterns, measures = c("Observed", "Shannon"))
div <- dfRowName(div, name = "SampleID")

# Take metadata from phyloseq object
div1 <- add_metadata(div, metad = GlobalPatterns, xid = "SampleID", mid = "X.SampleID")
head(div1)

# Or metadata from data frame
metad <- as(sample_data(GlobalPatterns), "data.frame")
div2 <- add_metadata(div, metad = metad, xid = "SampleID", mid = "X.SampleID")
head(div2)


vmikk/metagMisc documentation built on June 20, 2024, 7:20 a.m.