Data-Frame to (3D+) Array
d2a
converts a data.frame to a (3D+) array. This function assumes the
data.frame contains 3+ variable dimensions, which will correspond to the
returned arrays dimensions. One variable (and one variable only) must contain
the elements which will correspond to the elements of the returned array.
d2a(d, el.nm = "element", check = TRUE)
d |
data.frame with at least 4 columns, where 3+ columns are variable dimensions and 1 column contains the to-be array elements. The columns containing the variable dimensions do not need to be factors or character vectors. |
el.nm |
character vector of length 1 specifying the colname in |
check |
logical vector of length 1 specifying whether to check the structure
of the input arguments. For example, check whether |
d2a
is a wrapper for reshape::cast
with the addition of reordering
the dimnames by position, which sorts the dimnames by the position they first
appear in the variable dimensions of the data.frame (reshape::cast
) sorts
all the dimnames alphabetically).
(3D+) array containing the elements in d[[el.nm]]
. The dimlabels
are the colnames of d
other than el.nm
and the dimnames are the unique
elements in those columns. The dimnames are ordered by position (rather than
alphabetically), which allow for conversions back to the original array after
a call to a2d()
.
print(HairEyeColor) d <- reshape::melt.array(HairEyeColor) a <- reshape::cast(d, Hair ~ Eye ~ Sex) identical(a, unclass(HairEyeColor)) # not the same as HairEyeColor d <- a2d(HairEyeColor) a <- d2a(d) identical(a, unclass(HairEyeColor)) # yes the same as HairEyeColor
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.