Learn R Programming

mclink (version 1.1.1)

add_rows_if_not_exists: Add Missing Rows to a Data Frame

Description

This function checks if specified rows exist in a data frame, and if not, adds them with all values set to 0. Useful for ensuring consistent KO representation across samples.

Usage

add_rows_if_not_exists(
  module_abundance,
  add_rows = c("K14126", "K14128", "K14127")
)

Value

The original data frame with additional rows (if any were missing) where all values are set to 0. Row and column names are preserved.

Arguments

module_abundance

A data frame with row names representing KO identifiers (e.g., K numbers) and numeric abundance values

add_rows

A character vector of row names (KO identifiers) that should be present in the output. Defaults to c("K14126","K14128","K14127")