Skip to contents

check_column_vector() and check_is_column_vector() functions verify whether a given matrix is a column vector. check_column_vector() raises an error if the matrix is not a column vector, while check_is_column_vector() returns a logical value indicating whether the matrix is a column vector.

Usage

check_column_vector(mat, par_name = "mat")

check_is_column_vector(mat)

Arguments

mat

A matrix to check if it is a column vector.

par_name

An optional name of the parameter to display in error messages.

Value

  • check_column_vector(): Returns original value entered or raises an error message if an error occurs or any of the conditions is not met.

  • check_is_column_vector(): Logical value, TRUE if the matrix is a column vector, and FALSE otherwise.

Examples

# Examples for check_column_vector()
# ----------------------------------

A1 <- matrix(1:3, ncol = 1)
print(A1)
#>      [,1]
#> [1,]    1
#> [2,]    2
#> [3,]    3
check_column_vector(A1)
#>      [,1]
#> [1,]    1
#> [2,]    2
#> [3,]    3

A2 <- matrix(1:6, nrow = 2)
print(A2)
#>      [,1] [,2] [,3]
#> [1,]    1    3    5
#> [2,]    2    4    6
try(check_column_vector(A2))
#> Error in check_column_vector(A2) : 
#>   Expected 'mat' to be a matrix with only one column but got 3 columns

A3 <- matrix(c(5, 10, 15), ncol = 1)
print(A3)
#>      [,1]
#> [1,]    5
#> [2,]   10
#> [3,]   15
check_column_vector(A3)
#>      [,1]
#> [1,]    5
#> [2,]   10
#> [3,]   15

A4 <- matrix(1:4, nrow = 2, ncol = 2)
print(A4)
#>      [,1] [,2]
#> [1,]    1    3
#> [2,]    2    4
try(check_column_vector(A4))
#> Error in check_column_vector(A4) : 
#>   Expected 'mat' to be a matrix with only one column but got 2 columns

# Examples for check_is_column_vector()
# -------------------------------------

print(A1)
#>      [,1]
#> [1,]    1
#> [2,]    2
#> [3,]    3
check_is_column_vector(A1)
#> [1] TRUE

print(A2)
#>      [,1] [,2] [,3]
#> [1,]    1    3    5
#> [2,]    2    4    6
check_is_column_vector(A2)
#> [1] FALSE

print(A3)
#>      [,1]
#> [1,]    5
#> [2,]   10
#> [3,]   15
check_is_column_vector(A3)
#> [1] TRUE

print(A4)
#>      [,1] [,2]
#> [1,]    1    3
#> [2,]    2    4
check_is_column_vector(A4)
#> [1] FALSE