check_row_vector()
and check_is_row_vector()
functions check
if a given matrix is a row vector. check_row_vector()
raises an
error if the matrix is not a row vector, while check_is_row_vector()
returns a logical value indicating whether the matrix is a row vector.
Value
check_row_vector()
: Returns original value entered or raises an error message if an error occurs or any of the conditions is not met.check_is_row_vector()
: Logical value,TRUE
if the matrix is a row vector, andFALSE
otherwise.
Examples
# Examples for check_row_vector()
# -------------------------------
A1 <- matrix(1:3, nrow = 1)
print(A1)
#> [,1] [,2] [,3]
#> [1,] 1 2 3
check_row_vector(A1)
#> [,1] [,2] [,3]
#> [1,] 1 2 3
A2 <- matrix(1:6, ncol = 2)
print(A2)
#> [,1] [,2]
#> [1,] 1 4
#> [2,] 2 5
#> [3,] 3 6
try(check_row_vector(A2))
#> Error in check_row_vector(A2) :
#> Expected 'mat' to be a matrix with only one row but got 3 rows
A3 <- matrix(c(5, 10, 15), nrow = 1)
print(A3)
#> [,1] [,2] [,3]
#> [1,] 5 10 15
check_row_vector(A3)
#> [,1] [,2] [,3]
#> [1,] 5 10 15
# Examples for check_is_row_vector()
# ----------------------------------
check_is_row_vector(A1)
#> [1] TRUE
check_is_row_vector(A2)
#> [1] FALSE
check_is_row_vector(A3)
#> [1] TRUE