cond_log2_transform_matrix: Apply log2 transformation on a matrix.

View source: R/accessory.R

cond_log2_transform_matrixR Documentation

Apply log2 transformation on a matrix.

Description

Apply log2 transformation on a matrix.

Usage

cond_log2_transform_matrix(
  matrix_data,
  should_log = NULL,
  threshold = 20,
  rmzeros = FALSE,
  small_value = 1
)

Arguments

matrix_data

A matrix containing data.

should_log

A boolean indicating if the log2 transformation should be applied. If TRUE, log2 transformation is applied unconditionally. If FALSE, no transformation is applied. If NULL, a conditional transformation based on threshold is applied.

threshold

A numeric threshold to determine if the matrix should be log-transformed. This is only checked if should_log is NULL.

rmzeros

A boolean indicating whether to remove zeros from the matrix. If TRUE, zeros are removed. Default is FALSE.

small_value

A small value to add to zero entries before log transformation.

Value

A modified matrix.

Examples

# Create a sample matrix
mat <- matrix(c(10, 0, 30, 0, 50, 60), ncol = 2)

# Use the function with different parameters
transformed_mat1 <- cond_log2_transform_matrix(mat, should_log = TRUE)
transformed_mat2 <- cond_log2_transform_matrix(mat, should_log = NULL, threshold = 40)
transformed_mat3 <- cond_log2_transform_matrix(mat, rmzeros = TRUE)

pinin4fjords/shinyngs documentation built on Feb. 28, 2024, 10:19 a.m.