| makeNd {arrayhelpers} | R Documentation |
n dimensions and restore the old dimensionsnameNd ensures a given number of dimensions:
If a has less than N dimensions, new dimensions of length 1 are appended.
If a has more than N dimensions, the supernumerary dimensions are collapsed onto
the last dimension.
Attributes old.dim and old.dimnames are used by default. restoredim is the
inverse of makeNd.
makeNd(a, N) restoredim(a, old = NULL, n = 1L, ..., usedim = TRUE, fromend = FALSE, drop = FALSE)
a |
an array (matrix, vector) |
N |
the desired number of dimensions, 0 to remove the |
old |
list containing a list with (possibly) elements |
n |
how many makeNdim steps to go back? |
... |
ignored |
usedim |
use only the specified dimensions |
fromend |
if |
drop |
should 1d arrays drop to vectors? |
Note that missing attributes as well as old.dim = NULL produce a (dimensionless)
vector. This is also the case if a lost the old.* attributes during
computations like as.numeric, c, etc..
fromend together with numeric usedim specifies dimensions counting from the
end. E.g. fromend = TRUE and usedim = 1 : 3 for an array to be restored to 10d
means restoring dimensions 8 : 10. fromend = TRUE and usedim = -(1 : 3) restores
dimensions 1 to 7.
N-dimensional array
an array
Claudia Beleites
Claudia Beleites
v <- arrayhelpers:::v v makeNd (v, 1) dim (makeNd (v, 1)) dim (makeNd (v, 3)) m <- arrayhelpers:::m m makeNd (m, 1) dim (makeNd (m, 1)) makeNd (m, 0) dim (makeNd (m, 0)) makeNd (m, 3) a <- arrayhelpers:::a a dim (makeNd (a, 1)) dim (makeNd (a, 0)) makeNd (a, 2) makeNd (a, -2) makeNd (a, -4) makeNd (a, 3); a <- array (1 : 24, 4 : 3) a restoredim (makeNd (a, 0)) x <- makeNd (a, 0) attr (x, "old")