View source: R/ProcessMultiBlock.R
| ProcessMultiBlock | R Documentation |
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.
ProcessMultiBlock(
MB = MB,
blocks = NULL,
vars = NULL,
FUN = NULL,
FUN.SelectVars = NULL,
FUN.SelectBlocks = NULL
)
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 |
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 |
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 |
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.
MultiBlock, MultiBlock2Matrix
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.