Skip to contents

Repeat a vector or matrix a specific number of times.

Usage

repmat(x, m, n)

Arguments

x

A vector or matrix.

m

Integer specifying how many times to repeat x in the first dimension.

n

Integer specifying how many times to repeat x in the second dimension.

Value

A block matrix of dimension m*nrow(x) by n*ncol(x).

Examples

repmat(1:3, 3, 2) # will have dimension 9 by 2
#>       [,1] [,2]
#>  [1,]    1    1
#>  [2,]    2    2
#>  [3,]    3    3
#>  [4,]    1    1
#>  [5,]    2    2
#>  [6,]    3    3
#>  [7,]    1    1
#>  [8,]    2    2
#>  [9,]    3    3
repmat(randn(2, 2), 3, 2)
#>            [,1]      [,2]       [,3]      [,4]
#> [1,] -0.7373943 0.1351014 -0.7373943 0.1351014
#> [2,]  0.8497076 1.5209248  0.8497076 1.5209248
#> [3,] -0.7373943 0.1351014 -0.7373943 0.1351014
#> [4,]  0.8497076 1.5209248  0.8497076 1.5209248
#> [5,] -0.7373943 0.1351014 -0.7373943 0.1351014
#> [6,]  0.8497076 1.5209248  0.8497076 1.5209248