Returns a new matrix, where the entries of the original matrix are repeated along both dimensions.

# S3 method for matrix
rep(x, times = 1, each = 1, times.row = times,
  times.col = times, each.row = each, each.col = each, ...)

Arguments

x

a matrix

times

how often the matrix should be replicated next to itself

each

how often individual cells should be replicated next to themselves

times.row

number of vertical repetitions of the matrix, overrides times

times.col

number of horizontal repetitions of the matrix, overrides times

each.row

number of vertical repetitions of individual elements, overrides each

each.col

number of horizontal repetitions of individual elements, overrides each

...

not used

Value

A matrix, which will have times*each times more rows and columns than the original matrix.

See also

Examples

rep.matrix(diag(4))
#> [,1] [,2] [,3] [,4] #> [1,] 1 0 0 0 #> [2,] 0 1 0 0 #> [3,] 0 0 1 0 #> [4,] 0 0 0 1
rep.matrix(diag(4), times=2)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] #> [1,] 1 0 0 0 1 0 0 0 #> [2,] 0 1 0 0 0 1 0 0 #> [3,] 0 0 1 0 0 0 1 0 #> [4,] 0 0 0 1 0 0 0 1 #> [5,] 1 0 0 0 1 0 0 0 #> [6,] 0 1 0 0 0 1 0 0 #> [7,] 0 0 1 0 0 0 1 0 #> [8,] 0 0 0 1 0 0 0 1
rep.matrix(diag(4), each=2)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] #> [1,] 1 1 0 0 0 0 0 0 #> [2,] 1 1 0 0 0 0 0 0 #> [3,] 0 0 1 1 0 0 0 0 #> [4,] 0 0 1 1 0 0 0 0 #> [5,] 0 0 0 0 1 1 0 0 #> [6,] 0 0 0 0 1 1 0 0 #> [7,] 0 0 0 0 0 0 1 1 #> [8,] 0 0 0 0 0 0 1 1
rep.matrix(diag(3), times=2, each=2)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] #> [1,] 1 1 0 0 0 0 1 1 0 0 0 0 #> [2,] 1 1 0 0 0 0 1 1 0 0 0 0 #> [3,] 0 0 1 1 0 0 0 0 1 1 0 0 #> [4,] 0 0 1 1 0 0 0 0 1 1 0 0 #> [5,] 0 0 0 0 1 1 0 0 0 0 1 1 #> [6,] 0 0 0 0 1 1 0 0 0 0 1 1 #> [7,] 1 1 0 0 0 0 1 1 0 0 0 0 #> [8,] 1 1 0 0 0 0 1 1 0 0 0 0 #> [9,] 0 0 1 1 0 0 0 0 1 1 0 0 #> [10,] 0 0 1 1 0 0 0 0 1 1 0 0 #> [11,] 0 0 0 0 1 1 0 0 0 0 1 1 #> [12,] 0 0 0 0 1 1 0 0 0 0 1 1
rep.matrix(diag(4), each.row=2)
#> [,1] [,2] [,3] [,4] #> [1,] 1 0 0 0 #> [2,] 1 0 0 0 #> [3,] 0 1 0 0 #> [4,] 0 1 0 0 #> [5,] 0 0 1 0 #> [6,] 0 0 1 0 #> [7,] 0 0 0 1 #> [8,] 0 0 0 1
rep.matrix(diag(4), times.row=2)
#> [,1] [,2] [,3] [,4] #> [1,] 1 0 0 0 #> [2,] 0 1 0 0 #> [3,] 0 0 1 0 #> [4,] 0 0 0 1 #> [5,] 1 0 0 0 #> [6,] 0 1 0 0 #> [7,] 0 0 1 0 #> [8,] 0 0 0 1