cp_rel_abundance: Calculate CP Relative or Absolute Abundance

View source: R/ecological_indices.R

cp_rel_abundanceR Documentation

Calculate CP Relative or Absolute Abundance

Description

This function calculates the relative or absolute abundance of nematodes in different CP (Colonizer-Persister) groups for each sample. The CP groups range from CP1 (colonizers, r-strategists) to CP5 (persisters, K-strategists). Genera without CP classification are grouped as No_CP.

Usage

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

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

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

## Default S3 method:
cp_rel_abundance(data, total.abundance = NULL, relative = TRUE, ...)

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).

Value

A data frame with seven columns:

Sample.ID

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

CP1

Relative or absolute abundance of CP1 group (colonizers, r-strategists)

CP2

Relative or absolute abundance of CP2 group

CP3

Relative or absolute abundance of CP3 group

CP4

Relative or absolute abundance of CP4 group

CP5

Relative or absolute abundance of CP5 group (persisters, K-strategists)

No_CP

Relative or absolute abundance of genera without CP classification (only present if such genera exist)

Examples

# 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")
)
cp_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")
cp_rel_abundance(mat)

Nematode documentation built on April 7, 2026, 5:08 p.m.