Create new matrix copying dimensions from the existing one

with_same_dims(mat, data)

Arguments

mat

a matrix with desired dimensions

data

sigle numeric value or numeric vector

Value

a matrix

Examples

x <- matrix(7, 3, 6) x
#> [,1] [,2] [,3] [,4] [,5] [,6] #> [1,] 7 7 7 7 7 7 #> [2,] 7 7 7 7 7 7 #> [3,] 7 7 7 7 7 7
with_same_dims(x, 0)
#> [,1] [,2] [,3] [,4] [,5] [,6] #> [1,] 0 0 0 0 0 0 #> [2,] 0 0 0 0 0 0 #> [3,] 0 0 0 0 0 0
with_same_dims(x, c(1, 2))
#> [,1] [,2] [,3] [,4] [,5] [,6] #> [1,] 1 2 1 2 1 2 #> [2,] 2 1 2 1 2 1 #> [3,] 1 2 1 2 1 2