array_drop | R Documentation |
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.
array_drop(x, i)
x |
An array |
i |
Index or indices of dimensions to remove |
An array
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.