Learn R Programming

omicsTools (version 1.1.7)

handle_missing_values: Handle Missing Values in a Tibble

Description

This function filters features based on a missing value threshold and imputes missing values using various methods. Metadata columns are specified by the user and are exempt from filtering and imputation.

Usage

handle_missing_values(
  data,
  threshold = 0.2,
  imputation_method = "half_min",
  metadata_cols = NULL
)

Value

A tibble with filtered features and imputed missing values.

Arguments

data

A tibble containing the data with potential missing values.

threshold

A numeric value between 0 and 1 representing the maximum allowable proportion of missing values in a feature. Default is 0.20.

imputation_method

A character string indicating the method to use for imputation. Valid methods are "mean", "median", "mode", and "half_min". Default is "mean".

metadata_cols

A vector of column names or indices to be treated as metadata, exempt from filtering and imputation. Default is NULL.

Author

Yaoxiang Li

Examples

Run this code
data <- tibble::tibble(
  Feature1 = c(1, 2, NA, 4, 5),
  Feature2 = c(NA, 2, 3, 4, NA),
  Feature3 = c(1, NA, 3, NA, 5),
  Metadata = c("A", "B", "C", "D", "E")
)
imputed_data <- handle_missing_values(
  data,
  threshold = 0.20,
  imputation_method = "half_min",
  metadata_cols = "Metadata"
)
print(imputed_data)

Run the code above in your browser using DataLab