Fast generation of a matrix by replicating a matrix row- and column-wise in a block-like fashion

repmat(x, nrow = 1L, ncol = 1L)

Arguments

x

A matrix with dimensions r*c.

nrow

An integer giving the number of times the matrix is replicated row-wise

ncol

An integer giving the number of times the matrix is replicated column-wise

Value

A matrix with dimensions (r*nrow) x (c*ncol)

Examples

m <- matrix(1:6, ncol=3) repmat(m, 2) # Stack two copies of m on top of each other
#> [,1] [,2] [,3] #> [1,] 1 3 5 #> [2,] 2 4 6 #> [3,] 1 3 5 #> [4,] 2 4 6
repmat(m, 2, 3) # Replicate m with two copies on top and three copies side-by-side
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] #> [1,] 1 3 5 1 3 5 1 3 5 #> [2,] 2 4 6 2 4 6 2 4 6 #> [3,] 1 3 5 1 3 5 1 3 5 #> [4,] 2 4 6 2 4 6 2 4 6