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)

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, ]
#> [1]  1  5  9 13 17 21

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