Learn R Programming

turner (version 0.1.5)

matrix_to_blocks: Split a matrix into blocks

Description

Split a matrix into a list of blocks (either by rows or by columns)

Usage

matrix_to_blocks(Matrix, blocks, byrow = TRUE)

Arguments

Matrix
a matrix to split
blocks
either a list or a vector indicating the blocks. If blocks is a list of vectors, then the length of each vector defines the size of the blocks. If blocks is a vector, then each element represents the size of the blocks.
byrow
logical. If TRUE (the default) the matrix is split by rows, otherwise the matrix is split by columns

Value

  • A list of matrices

See Also

lengths, listsize

Examples

Run this code
# matrix with 10 rows and 7 columns
M = matrix(rnorm(70), 10, 7)

# row blocks
row_sets = list(1:3, 4:5, 6:10)

# split matrix by rows
matrix_to_blocks(M, row_sets)

# column blocks
col_sets = c(3, 4)

# split matrix by rows
matrix_to_blocks(M, col_sets, byrow=FALSE)

Run the code above in your browser using DataLab