Replicate array elements
arep.Rd
arep_times()
and arep_each()
are multidimensional
versions of base::rep( , times=)
and base::rep( , each=)
,
respectively.
They're both generic functions with default methods that work on any
array-like object that supports [
(single-bracket subsetting).
Value
An array-like object of the same class as x
and with dimensions
dim(x) * times
for arep_times
or dim(x) * each
for arep_each
.
The dimnames on x
are propagated, if any.
Examples
m <- matrix(1:10, nrow=2)
arep_times(m, c(4, 2))
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> [1,] 1 3 5 7 9 1 3 5 7 9
#> [2,] 2 4 6 8 10 2 4 6 8 10
#> [3,] 1 3 5 7 9 1 3 5 7 9
#> [4,] 2 4 6 8 10 2 4 6 8 10
#> [5,] 1 3 5 7 9 1 3 5 7 9
#> [6,] 2 4 6 8 10 2 4 6 8 10
#> [7,] 1 3 5 7 9 1 3 5 7 9
#> [8,] 2 4 6 8 10 2 4 6 8 10
arep_each(m, c(4, 2))
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> [1,] 1 1 3 3 5 5 7 7 9 9
#> [2,] 1 1 3 3 5 5 7 7 9 9
#> [3,] 1 1 3 3 5 5 7 7 9 9
#> [4,] 1 1 3 3 5 5 7 7 9 9
#> [5,] 2 2 4 4 6 6 8 8 10 10
#> [6,] 2 2 4 4 6 6 8 8 10 10
#> [7,] 2 2 4 4 6 6 8 8 10 10
#> [8,] 2 2 4 4 6 6 8 8 10 10
## Note that the output array is 'prod(times)' (or 'prod(each)') times
## bigger than the input array!