Learn R Programming

neuroim2 (version 0.8.5)

split_blocks: Cut a vector-valued object into a list of sub-blocks

Description

Splits a vector-valued object into a list of sub-blocks defined by a vector of indices.

Usage

split_blocks(x, indices, ...)

# S4 method for NeuroVec,integer split_blocks(x, indices, ...)

# S4 method for NeuroVec,factor split_blocks(x, indices, ...)

# S4 method for NeuroVec,factor split_blocks(x, indices, ...)

Value

A list of sub-blocks, where each sub-block contains the elements from x corresponding to the matching indices.

Arguments

x

a vector-valued object

indices

a vector of indices defining the sub-blocks. Must match the length of the input vector.

...

additional arguments

Examples

Run this code
# Create a 4D neuroimaging vector with 20 timepoints
space <- NeuroSpace(c(10,10,10,20), c(1,1,1))
vec <- NeuroVec(array(rnorm(10*10*10*20), c(10,10,10,20)), space)

# Split into 4 blocks by assigning timepoints to blocks 1-4 repeatedly
block_indices <- rep(1:4, length.out=20)
blocks <- split_blocks(vec, block_indices)

Run the code above in your browser using DataLab