array_reshape: Rehape an array dimension

View source: R/arrays.R

array_reshapeR Documentation

Rehape an array dimension

Description

Reshape one dimension of a multidimensional array. Use this to say that some dimension (say with length 20) actually represents a number of other dimensions (e.g., 2 x 10 or 2 x 2 x 5). This might be the case if you've been doing a simulation with a large number of parameter sets that are pooled over some other grouping factors (e.g., in a sensitivity analysis)

Usage

array_reshape(x, i, d)

Arguments

x

An array

i

The index of the dimension to expand

d

The new dimensions for data in the i'th dimension of x

Value

A multidimensional array

See Also

array_flatten which undoes this operation

Examples

# Suppose we had a 4 x 6 array of data:
m <- matrix(1:24, 4, 6)

# And suppose that the second dimension really represented a 2 x 3
# matrix; so that looking at one copy of the 2nd dimension we see
m[1, ]

# But instead we might want to see
res <- mcstate::array_reshape(m, 2, c(2, 3))
res[1, , ]

mrc-ide/mcstate documentation built on July 3, 2024, 1:34 p.m.