This is the inverse operation of base::drop()
.
It is analogous to python's numpy.expand_dims()
, but vectorized on
which_dim
.
expand_dims(x, which_dim = -1L)
x | an array. Bare vectors are treated as 1-d arrays. |
---|---|
which_dim | numeric. Desired index position of the new axis or axes in the returned array. Negative numbers count from the back. Can be any length.Throws a warning if any duplicates are provided. |
the array x
with new dim
#> [1] 2 3 4#> [1] 2 3 4 1#> [1] 2 1 3 4#> [1] 1 1 2 3 4#> [1] 1 2 3 4 1#> [1] 2 3 4 1 1 1#> [1] 2 3 4 1 1 1#> Error in expand_dims(x, -6) : #> Implicit additional dims for expansion with negative indexes not supported#> [1] 1 1 1 2 3 4