bind_as_* introduces a new dimension, such that each element in list_of_arrays corresponds to one index position along the new dimension in the returned array. bind_on_* binds all elements along an existing dimension, (meaning, the returned array has the same number of dimensions as each of the arrays in the list).

bind_as_dim(list_of_arrays, which_dim)

bind_as_rows(...)

bind_as_cols(...)

bind_on_dim(list_of_arrays, which_dim)

bind_on_rows(...)

bind_on_cols(...)

Arguments

list_of_arrays

a list of arrays. All arrays must be of the same dimension. NULL's in place of arrays are automatically dropped.

which_dim

Scalar integer specifying the index position of where to introduce the new dimension to introduce. Negative numbers count from the back. For example, given a 3 dimensional array, -1, is equivalent to 3, -2 to 2 and -3 to 1.

...

Arrays to be bound, specified individually or supplied as a single list

Value

An array, with one additional dimension.

Details

bind_*_rows() is a wrapper for the common case of bind_*_dim(X, 1). bind_*_cols() is a wrapper for the common case of bind_*_dim(X, -1).

Examples

list_of_arrays <- replicate(10, array(1:8, dim = c(2,3,4)), FALSE) dim(list_of_arrays[[1]])
#> [1] 2 3 4
# bind on a new dimension combined_as <- bind_as_rows(list_of_arrays) dim(combined_as)
#> [1] 10 2 3 4
dim(combined_as)[1] == length(list_of_arrays)
#> [1] TRUE
# each element in `list_of_arrays` corresponds to one "row" # (i.e., one entry in along the first dimension) for(i in seq_along(list_of_arrays)) stopifnot(identical(combined_as[i,,,], list_of_arrays[[i]])) # bind on an existing dimension combined_on <- bind_on_rows(list_of_arrays) dim(combined_on)
#> [1] 20 3 4
dim(combined_on)[1] == sum(sapply(list_of_arrays, function(x) dim(x)[1]))
#> [1] TRUE
identical(list_of_arrays[[1]], combined_on[1:2,,])
#> [1] TRUE
for (i in seq_along(list_of_arrays)) stopifnot(identical( list_of_arrays[[i]], combined_on[ (1:2) + (i-1)*2,,] )) # bind on any dimension combined <- bind_as_dim(list_of_arrays, 3) dim(combined)
#> [1] 2 3 10 4
for(i in seq_along(list_of_arrays)) stopifnot(identical(combined[,,i,], list_of_arrays[[i]]))