Learn R Programming

broadcast (version 0.1.7)

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)

Value

Returns the replicated array.

Arguments

x

an atomic or recursive array or matrix.

tdim

an integer vector, giving the target dimension to reach.

Examples

Run this code

x <- matrix(1:9, 3,3)
colnames(x) <- LETTERS[1:3]
rownames(x) <- letters[1:3]
names(x) <- month.abb[1:9]
print(x)

rep_dim(x, c(3,3,2)) # replicate to larger size

Run the code above in your browser using DataLab