Learn R Programming

SSBtools (version 1.8.2)

zero_col: Check for empty matrix columns (or rows)

Description

More generally, checks that both row/col sums and sums of absolute values equal a target. For value = 0, this means all entries are zero. single_col() is a wrapper with value = 1, often used to check for dummy columns/rows with exactly one element that is 1.

Usage

zero_col(x, rows = FALSE, value = 0)

single_col(..., value = 1)

Value

Logical vector.

Arguments

x

Numeric matrix. Sparse matrices from the Matrix package are also supported.

rows

Logical; if TRUE check rows, else columns.

value

Numeric target (default 0).

...

Passed to zero_col().

Details

Memory usage is reduced by applying abs() checks only to rows/columns whose total sum is already the target.

Examples

Run this code
m <- matrix(c(
  0,  0, 0, 0, 
  1, -1, 0, 0,
  0,  0, 1, 0
), nrow = 3, byrow = TRUE)

zero_col(m)
zero_col(m, rows = TRUE)
single_col(m)
single_col(m, rows = TRUE)

Run the code above in your browser using DataLab