array_drop: Drop specific array dimensions

View source: R/arrays.R

array_dropR Documentation

Drop specific array dimensions

Description

Drop specific array dimensions that are equal to 1. This a more explicit, safer version of drop, which requires you indicate which dimensions will be dropped and errors if dimensions can't be dropped.

Usage

array_drop(x, i)

Arguments

x

An array

i

Index or indices of dimensions to remove

Value

An array

Examples


# Suppose we have an array with a redundant 2nd dimension
m <- array(1:25, c(5, 1, 5))

# commonly we might drop this with
drop(m)

# in this case, array_drop is the same:
mcstate::array_drop(m, 2)

# However, suppose that our matrix had, in this case, a first
# dimension that was also 1 but we did not want to drop it:
m2 <- m[1, , , drop = FALSE]

# Here, drop(m2) returns just a vector, discarding our first dimension
drop(m2)

# However, array_drop will preserve that dimension
mcstate::array_drop(m2, 2)

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