ProcessMultiBlock: ProcessMultiBlock

View source: R/ProcessMultiBlock.R

ProcessMultiBlockR Documentation

ProcessMultiBlock

Description

Apply a custom function to transform a MultiBlock and/or select variables or blocks. When multiple operations are supplied, the order of execution is: vars subsetting, then FUN, then FUN.SelectVars, then FUN.SelectBlocks.

Usage

ProcessMultiBlock(
  MB = MB,
  blocks = NULL,
  vars = NULL,
  FUN = NULL,
  FUN.SelectVars = NULL,
  FUN.SelectBlocks = NULL
)

Arguments

MB

A MultiBlock object.

blocks

The blocks to process. A vector of integers or block names. When omitted, all blocks are processed.

vars

The variables to keep. A list with the same length as blocks. Each element contains the indices (integer) or names (character) of the variables to retain in that block. Subsetting is applied before any of the FUN arguments.

FUN

A function applied to each selected block's data matrix (samples x variables). It receives the matrix as its sole argument and must return a matrix of the same dimensions.

FUN.SelectVars

A function applied to each selected block's data matrix to determine which variables to keep. It receives the matrix as its sole argument and must return a logical vector of length equal to ncol of the matrix (TRUE = keep).

FUN.SelectBlocks

A function applied to each selected block's data matrix to determine whether the block should be retained. It receives the matrix as its sole argument and must return a single TRUE or FALSE.

Value

The processed MultiBlock object, with data matrices transformed and/or blocks/variables removed according to the supplied arguments. Blocks not listed in blocks are left unchanged.

See Also

MultiBlock, MultiBlock2Matrix

Examples

b1 <- matrix(rnorm(500), 10, 50)
b2 <- matrix(rnorm(800), 10, 80)
mb <- MultiBlock(Data = list(b1 = b1, b2 = b2))
# Normalize each block to 0-100 range
BY100 <- function(x) 100 * (x - min(x)) / (max(x) - min(x))
mb <- ProcessMultiBlock(mb, FUN = BY100)
# Keep only variables with non-zero variance
mb <- ProcessMultiBlock(mb, FUN.SelectVars = function(x) apply(x, 2, var) > 0)
# Remove blocks where all values are below 0.5
mb <- ProcessMultiBlock(mb, FUN.SelectBlocks = function(x) max(x) >= 0.5)

R.ComDim documentation built on May 13, 2026, 9:07 a.m.