Learn R Programming

eDNAfuns (version 0.1.0)

tibble_to_comm: Convert a long tibble to a community matrix

Description

Converts a long-format table of sequence counts into a wide community matrix (samples × taxa) suitable for vegan or other community ecology tools.

Produces a distance matrix between samples using vegan's vegdist(). Optionally applies a data transformation before distance calculation.

Returns the environmental data frame (sample metadata) from a long sequence/OTU tibble by removing taxon and abundance columns.

Usage

tibble_to_comm(long.table, taxon, Abundance, sample.name)

tibble_to_dist( long.table, taxon, Abundance, sample.name, distance = "bray", transformation = NULL, ... )

tibble_to_env(long.table, taxon, Abundance, sample.name, ...)

Value

A numeric matrix with taxa as columns and samples as row names.

A dist object.

A tibble of unique sample-level metadata.

Arguments

long.table

A tibble with sample, taxon, abundance, and metadata columns.

taxon

Column containing taxa/OTU IDs (unquoted).

Abundance

Column with counts/abundance values (unquoted).

sample.name

Column with sample IDs (unquoted).

distance

Distance metric to use (default = "bray").

transformation

Optional transformation (e.g. "hellinger", "log"). See vegan::decostand documentation for a great explanation of all transformations

...

Additional metadata columns to retain.

Examples

Run this code
data("ASV_table")
 tibble_to_comm(ASV_table, 
                taxon = Hash,
                 Abundance = nReads,
                  sample.name = sample_name)
data("ASV_table")
tibble_to_dist(ASV_table,
               taxon = Hash,
               Abundance = nReads,
               sample.name = sample_name,
               distance = "bray",
               transformation = "hellinger")

data("ASV_table")
data("metadata")
dplyr::inner_join(ASV_table,metadata) |> 
tibble_to_env(taxon = Hash,
              Abundance = nReads, 
              sample.name = sample_name)

Run the code above in your browser using DataLab