assertRowsAndColumns: Assert Row and Column Names of a Matrix

View source: R/matrix.R

assertRowsAndColumnsR Documentation

Assert Row and Column Names of a Matrix

Description

Make sure that a matrix contains rows and columns of the given names in the given order.

Usage

assertRowsAndColumns(x, row_names = NULL, col_names = NULL, fill_value = 0)

Arguments

x

A matrix

row_names

character vector of row names

col_names

character vector of column names

fill_value

value to fill a row or column with if a row or column does not exist in x

Examples

m <- matrix(1:12, nrow = 3, ncol = 4, dimnames = list(
  rows = paste0("row", 1:3), cols = paste0("col", 1:4)
))

# Add two rows, reverse order of rows, add one column, remove one column
assertRowsAndColumns(
  m,
  row_names = paste0("row", 4:0),
  col_names = paste0("col", 0:2)
)


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