Learn R Programming

diagonals (version 0.2.0)

rectangle_matrix: Rectangle Matrix

Description

Rectangle Matrix

Usage

rectangle_matrix(x, steps = NULL, size = NULL, replacement = 0)

Arguments

x
a matrix where the dimensions are both multiples of size
steps
the required number of steps (block matrices) across the diagonal
size
the largest dimension of the matrix being selected over the diagonal of matrix
replacement
value to be inserted off the diagonal, by default this is zero (0).

Examples

Run this code
# create a non-square matrix
nsm <- matrix(1:27, nrow=9, ncol=3 )

# check that both dimensions are multiples of steps=3
dim(nsm) %% 3 == c(0, 0)

# select the diagonal matrix
rectangle_matrix(nsm, steps=3)

Run the code above in your browser using DataLab