library("broadcast")
<- matrix(1:9, 3,3)
x colnames(x) <- LETTERS[1:3]
rownames(x) <- letters[1:3]
names(x) <- month.abb[1:9]
print(x)
## A B C
## a 1 4 7
## b 2 5 8
## c 3 6 9
## attr(,"names")
## [1] "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep"
rep_dim(x, c(3,3,2)) # replicate to larger size
## , , 1
##
## A B C
## a 1 4 7
## b 2 5 8
## c 3 6 9
##
## , , 2
##
## A B C
## a 1 4 7
## b 2 5 8
## c 3 6 9
rep_dim
Replicate Array Dimensions
Description
The rep_dim()
function replicates array dimensions until the specified dimension sizes are reached, and returns the array.
The various broadcasting functions recycle array dimensions virtually, meaning little to no additional memory is needed.
The rep_dim()
function, however, physically replicates the dimensions of an array (and thus actually occupies additional memory space).
Usage
rep_dim(x, tdim)
Arguments
x
|
an atomic or recursive array or matrix. |
tdim
|
an integer vector, giving the target dimension to reach. |
Value
Returns the replicated array.