Learn R Programming

somhca (version 0.3.0)

loadMatrix: Load Data and Convert to a Matrix

Description

Loads data from a CSV file or an in-memory object (data frame or matrix), optionally removes specified columns, and applies specified normalization methods before converting the data to a matrix. In the original dataset, rows represent observations (e.g., samples), columns represent variables (e.g., features), and all cells (except for column headers and, if applicable, row headers) must only contain numeric values.

Usage

loadMatrix(
  input,
  remove_columns = NULL,
  remove_row_headings = FALSE,
  scaling = "no"
)

Value

A matrix with the processed data.

Arguments

input

A string specifying the path to the CSV file, or an in-memory object (data frame or matrix).

remove_columns

Optional integer, character, or vector of either. If specified, removes the columns of the dataset indicated by position or name. This is useful, for example, when the first column contains non-numeric identifiers (e.g., sample names) that should be excluded from the analysis. Default is `NULL`.

remove_row_headings

Deprecated, use `remove_columns = 1` instead. A logical value. If `TRUE`, removes the first column of the dataset. Default is `FALSE`.

scaling

A string specifying the scaling method. Options are:

"no"

No scaling is applied (default).

"simpleFeature"

Each column is divided by its maximum value.

"minMax"

Each column is scaled to range [0, 1].

"zScore"

Each column is Z-score standardized.

Examples

Run this code
# Example 1: Load toy data from a CSV file
file_path <- system.file("extdata", "toy_data.csv", package = "somhca")

# Run the loadMatrix function with the mock data
myMatrix <- loadMatrix(file_path, remove_columns = 1, scaling = "minMax")

# Example 2: Load from a toy data frame
df <- data.frame(
  ID = paste0("Sample", 1:100), # Character column for row headings
  matrix(rnorm(900), nrow = 100, ncol = 9) # Numeric data
)

# Run the loadMatrix function with the mock data
myMatrix <- loadMatrix(df, remove_columns = 1, scaling = "zScore")

# Example 3: Load from a toy matrix
mat <- matrix(rnorm(900), nrow = 100, ncol = 9) # Numeric data

# Run the loadMatrix function with the mock data
myMatrix <- loadMatrix(mat, scaling = "simpleFeature")

Run the code above in your browser using DataLab