Learn R Programming

Nematode (version 0.2.0)

diet_rel_abundance: Calculate Diet Relative or Absolute Abundance

Description

TThis function calculates the relative or absolute abundance of four feeding types of nematodes in each sample. The feeding types include bacterial feeders (Ba), fungus feeders (Fu), plant feeders (Pp), and omnivores/predators (Op).

Usage

diet_rel_abundance(data, total.abundance = NULL, relative = TRUE, ...)

# S3 method for data.frame diet_rel_abundance(data, total.abundance = NULL, relative = TRUE, ...)

# S3 method for matrix diet_rel_abundance(data, total.abundance = NULL, relative = TRUE, ...)

# S3 method for default diet_rel_abundance(data, total.abundance = NULL, relative = TRUE, ...)

Value

A data frame with five columns:

Sample.ID

Character vector of sample identifiers (from row names of data)

Ba

Relative or absolute abundance of bacterial feeders

Fu

Relative or absolute abundance of fungus feeders

Pp

Relative or absolute abundance of plant feeders

Op

Relative or absolute abundance of omnivores/predators

Arguments

data

data.frame or matrix. The nematode abundance table where rows represent samples and columns represent nematode genera. Each element indicates the count of a specific nematode genus in the corresponding sample. Row names must be sample names, and column names must be nematode genus names.

total.abundance

data.frame. A data frame with sample names as row names and a single column containing the total nematode abundance for each sample. This parameter is required when relative is set to FALSE. Default is NULL.

relative

Logical. If TRUE (default), the function calculates relative abundance (does not require total.abundance). If FALSE, the function calculates absolute abundance (requires total.abundance).

...

Additional arguments (currently unused).

Examples

Run this code
# Example with a data frame
df <- data.frame(
  Cephalobus = c(10, NA, 15),
  Caenorhabditis = c(5, 10, NA),
  Pratylenchus = c(8, 12, 10),
  row.names = c("A", "B", "C")
)
abundance <- data.frame(
  abundance = c(100, 150, 120),
  row.names = c("A", "B", "C")
)
diet_rel_abundance(df, abundance, relative = FALSE)

# Example with a matrix
mat <- matrix(c(10, NA, 15, 5, 10, NA, 8, 12, 10), nrow = 3, byrow = TRUE)
colnames(mat) <- c("Cephalobus", "Caenorhabditis", "Pratylenchus")
row.names(mat) <- c("A", "B", "C")
diet_rel_abundance(mat)

Run the code above in your browser using DataLab