iszero_byname: Test whether this is the zero matrix

Description Usage Arguments Value Examples

View source: R/Utilities.R

Description

Note that this function tests whether the elements of abs(a) are <= tol. So, you can set tol = 0 to discover if a is EXACTLY the zero matrix.

Usage

1
iszero_byname(a, tol = 1e-06)

Arguments

a

a matrix of list of matrices

tol

the allowable deviation from 0 for any element

Value

TRUE iff this is the zero matrix within tol.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
zero <- matrix(0, nrow = 50, ncol = 50)
iszero_byname(zero)
nonzero <- matrix(1:4, nrow = 2)
iszero_byname(nonzero)
# Also works for lists
iszero_byname(list(zero, nonzero))
# And it works for data frames
DF <- data.frame(A = I(list()), B = I(list()))
DF[[1,"A"]] <- zero
DF[[2,"A"]] <- nonzero
DF[[1,"B"]] <- nonzero
DF[[2,"B"]] <- zero
iszero_byname(DF$A)
iszero_byname(DF$B)
iszero_byname(matrix(1e-10, nrow = 2))
iszero_byname(matrix(1e-10, nrow = 2), tol = 1e-11)

matsbyname documentation built on July 8, 2020, 6:55 p.m.