num_species: Calculate Number of Species

View source: R/ecological_indices.R

num_speciesR Documentation

Calculate Number of Species

Description

This function calculates the number of nematode species present in each sample. It counts the number of non-zero and non-empty nematode species for each sample.

Usage

num_species(data, ...)

## S3 method for class 'data.frame'
num_species(data, ...)

## S3 method for class 'matrix'
num_species(data, ...)

## Default S3 method:
num_species(data, ...)

Arguments

data

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

...

Additional arguments (currently unused).

Value

A data.frame with two columns:

Sample.ID

Character vector of sample identifiers (from row names)

NumSpecies

Number of non-zero nematode species in each sample

Examples

# Example with a data frame
df <- data.frame(
  Species1 = c(10, NA, 15),
  Species2 = c(5, 10, NA),
  Species3 = c(8, 12, 10),
  row.names = c("A", "B", "C")
)
num_species(df)

# Example with a matrix
mat <- matrix(c(10, NA, 15, 5, 10, NA, 8, 12, 10), nrow = 3, byrow = TRUE)
colnames(mat) <- c("Species1", "Species2", "Species3")
row.names(mat) <- c("A", "B", "C")
num_species(mat)


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