Learn R Programming

RegSDC (version 1.0.0)

EnsureMatrix: Ensure that input is matrix (by as.matrix) and check number of rows (and columns)

Description

Ensure that input is matrix (by as.matrix) and check number of rows (and columns)

Usage

EnsureMatrix(x, nRow = NULL, nCol = NULL)

Value

Input as a matrix

Arguments

x

NULL or input to as.matrix

nRow

Expected number of rows

nCol

Expected number of columns

Author

Øyvind Langsrud

Examples

Run this code
x <- matrix(c(5, 8, 4, 2, 7, 6), 3, 2)
EnsureMatrix(x)
EnsureMatrix(x, 3)
EnsureMatrix(1:4)
EnsureMatrix(1:4, 4)
EnsureMatrix(NULL, 4)
try(EnsureMatrix(x, 4))
try(EnsureMatrix(1:3, 4))
EnsureMatrix(x, 3, 2)
try(EnsureMatrix(x, 3, 3))
try(EnsureMatrix(NULL, 3, 3))

Run the code above in your browser using DataLab