createMatrix: Matrix with Row and Column Names

View source: R/matrix.R

createMatrixR Documentation

Matrix with Row and Column Names

Description

Create a matrix by giving row and column names and with all elements being set to a default value

Usage

createMatrix(
  rowNames,
  colNames = rowNames,
  value = 0,
  name.row = NULL,
  name.col = NULL
)

Arguments

rowNames

character vector of row names to be given to the matrix

colNames

character vector of column names to be given to the matrix

value

value to be given to each matrix element

name.row

optional. Name to be given to the row dimension

name.col

optional. Name to be given to the column dimension

Value

matrix with rowNames as row names and colNames as column names, filled with value at each position

Examples

## Initialise a matrix with rows A to E and columns x to z of value -1
createMatrix(c("A", "B", "C", "D", "E"), c("x", "y", "z"), -1)

## By default the column names are assumed to be equal to the row names
createMatrix(c("A", "B", "C"))

## Initialise a square matrix with NA
createMatrix(c("A", "B", "C"), value = NA)

## Give a name to the row dimension
createMatrix(c("A", "B", "C"), name.row = "Letters")


KWB-R/kwb.utils documentation built on April 1, 2024, 7:12 a.m.