check_matrix_constant() and check_is_matrix_constant() check
whether a matrix contains constant (same) values.
check_is_matrix_constant() raises an error if all the values of the
matrix are not the same, while check_is_matrix_constant() returns
TRUE if the matrix constant (same) values and FALSE otherwise.
Value
check_matrix_constant(): ReturnsNULLif the matrix contains constant (same) values, or raises an error if the matrix contains different values.check_is_matrix_constant(): Logical value,TRUEif the matrix constant (same) values andFALSEotherwise.
Examples
# Examples for check_matrix_constant()
# ------------------------------------
A <- matrix(5, nrow = 3, ncol = 3)
check_matrix_constant(A)
#> [,1] [,2] [,3]
#> [1,] 5 5 5
#> [2,] 5 5 5
#> [3,] 5 5 5
B <- matrix(c(5, 5, 5, 0, 5, 5), nrow = 2, ncol = 3)
print(B)
#> [,1] [,2] [,3]
#> [1,] 5 5 5
#> [2,] 5 0 5
try(check_matrix_constant(B))
#> Error in check_matrix_constant_with_k(mat = mat, par_name = par_name) :
#> Expected 'mat' to be a constants matrix
# Examples for check_is_matrix_constant()
# ---------------------------------------
check_is_matrix_constant(A)
#> [1] TRUE
check_is_matrix_constant(B)
#> [1] FALSE