Learn R Programming

Nematode (version 0.2.0)

num_species: 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 data.frame num_species(data, ...)

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

# S3 method for default num_species(data, ...)

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

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

Examples

Run this code
# 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)

Run the code above in your browser using DataLab