Skip to contents

stm_constant_like() generates a constant matrix or vector that matches the dimensions of the provided input matrix or vector.

Usage

stm_constant_like(vmat, k = 2)

Arguments

vmat

A matrix or vector whose dimensions will be used to generate the constant matrix or vector.

k

A numeric value representing the constant to fill the generated matrix or vector. Default is 2.

Value

A matrix or vector of the same dimensions as vmat, filled with the constant value k.

Details

The function checks the validity of the input vmat and k, converting vmat to a matrix if it is a vector. It then generates a matrix of the same size as vmat filled with the constant value k.

See also

Examples

A <- matrix(1:12, nrow = 3, byrow = TRUE)
print(A)
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    2    3    4
#> [2,]    5    6    7    8
#> [3,]    9   10   11   12
stm_constant_like(A, k = 5)
#>      [,1] [,2] [,3] [,4]
#> [1,]    5    5    5    5
#> [2,]    5    5    5    5
#> [3,]    5    5    5    5
stm_constant_like(c(1, 2, 3), k = 7)
#>      [,1]
#> [1,]    7
#> [2,]    7
#> [3,]    7