matrix_to_blocks: Split a matrix into blocks

Description Usage Arguments Value Author(s) See Also Examples

View source: R/matrix_to_blocks.r

Description

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

Usage

1
  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

Author(s)

Gaston Sanchez

See Also

lengths, listsize

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 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)

gastonstat/turner documentation built on May 16, 2019, 6:38 p.m.