split_by_block: Split variables by block ID

View source: R/all_generic.R

split_by_blockR Documentation

Split variables by block ID

Description

Split a vector or matrix of values into separate pieces based on block/run IDs. This function is useful for:

  • Separating data into individual runs

  • Processing blocks independently

  • Analyzing run-specific patterns

Usage

split_by_block(x, ...)

Arguments

x

The object containing data to split (typically a sampling_frame or dataset)

...

Additional arguments passed to methods

vals

The values to split by block (if not contained in x)

Value

A list where each element contains data from one block:

  • List length equals number of blocks

  • Each element contains values from one block

  • Order matches the original block sequence

See Also

sampling_frame(), blockids(), blocklens()

Other block_operations: blockids(), blocklens()

Examples

# Create a sampling frame with multiple runs
sframe <- sampling_frame(
  blocklens = c(50, 50, 50),  # 3 runs of 50 scans each
  TR = 2
)

# Create some example data
data_values <- rnorm(150)  # 150 values (50 per run)

# Split data by run
run_data <- split_by_block(sframe, data_values)
# Returns list with 3 elements, each containing 50 values

# Create matrix dataset
X <- matrix(rnorm(150 * 10), 150, 10)  # 150 timepoints, 10 voxels
dset <- matrix_dataset(
  X,
  TR = 2,
  run_length = c(50, 50, 50)
)

# Split matrix data by run
run_matrices <- split_by_block(dset)
# Returns list with 3 matrices, each 50 x 10

bbuchsbaum/fmrireg documentation built on March 1, 2025, 11:20 a.m.