Bind a number of arrays, usually by their last dimension. This is useful for binding together the sorts of arrays produced by dust and mcstate's simulation functions.

array_bind(..., arrays = list(...), dimension = NULL)

Arguments

...

Any number of arrays. All dimensions must the the same, except for the dimension being bound on which may vary.

arrays

As an alternative to using ... you can provide a list directly. This is often nicer to program with.

dimension

The dimension to bind on; by default NULL means the last dimension.

Value

A single array object

Examples

# Consider two matricies; this is equivalent to rbind and is
# pretty trivial
m1 <- matrix(1, 4, 5)
m2 <- matrix(2, 4, 2)
mcstate::array_bind(m1, m2)
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,]    1    1    1    1    1    2    2
#> [2,]    1    1    1    1    1    2    2
#> [3,]    1    1    1    1    1    2    2
#> [4,]    1    1    1    1    1    2    2

# For a 4d array though it's less obvious
a1 <- array(1, c(2, 3, 4, 5))
a2 <- array(2, c(2, 3, 4, 1))
a3 <- array(3, c(2, 3, 4, 3))
dim(mcstate::array_bind(a1, a2, a3))
#> [1] 2 3 4 9