vector2array() turns a vector into an array,
with a specific vector direction,
and turning the names into dimnames, and keeping (or forcing) broadcaster attribute.
undim() returns a copy of an object, but with its dimensions removed,
but still trying to keep the names if possible
(it somewhat is like the dimensional version of unlist()).
undim() will also keep (or force) the broadcaster attribute
array2vector() is an alias for undim().
vector2array(x, direction, ndim = direction, broadcaster = NULL)undim(x, broadcaster = NULL)
array2vector(x, broadcaster = NULL)
For vector2array():
If x is already an array, x is returned unchanged.
Otherwise, given out <- vector2array(x, direction, ndim),
out will be an array with the following properties:
ndim(out) == ndim;
dim(out)[direction] == length(x), and all other dimensions will be 1;
dimnames(out)[[direction]] == names(x), and all other dimnames will be NULL.
For undim():
If x is not an array, x is returned unchanged.
Otherwise, a copy of the original object, but without dimensions,
but keeping names and broadcaster attribute as far as possible.
an vector (for vector2array() or an array (for undim()/array2vector()).
All atomic types, and the recursive type list, are supported.
a positive integer scalar, giving the direction of the vector.
In other words: give here which dimension should have size length(x) - all other dimensions will have size 1.
the number of dimensions in total.
It must be the case that ndim >= direction, and ndim <= 16L.
TRUE or FALSE, indicating if the result should be a broadcaster.
If NULL, broadcaster(x) will be used.
x <- setNames(1:27, c(letters, NA))
print(x)
y <- vector2array(x, 1L, 3L)
print(y)
undim(y)
Run the code above in your browser using DataLab