Learn R Programming

s2dv (version 2.1.0)

InsertDim: Add a named dimension to an array

Description

Insert an extra dimension into an array at position 'posdim' with length 'lendim'. The array repeats along the new dimension.

Usage

InsertDim(data, posdim, lendim, name = NULL)

Value

An array as parameter 'data' but with the added named dimension.

Arguments

data

An array to which the additional dimension to be added.

posdim

An integer indicating the position of the new dimension.

lendim

An integer indicating the length of the new dimension.

name

A character string indicating the name for the new dimension. The default value is NULL.

Examples

Run this code
a <- array(rnorm(15), dim = c(a = 3, b = 1, c = 5, d = 1))
res <- InsertDim(InsertDim(a, posdim = 2, lendim = 1, name = 'e'), 4, c(f = 2))
dim(res)

Run the code above in your browser using DataLab