array2df {hyperSpec}R Documentation

array2df: Convert multidimensional array into matrix or data.frame

Description

The "wide-format" array is converted into a "long-format" matrix or data.frame.

Usage

array2df(x, levels = rep(NA, length(dims)), matrix = FALSE, label.x = deparse(substitute(x)))

Arguments

x array
levels list with the levels for the dimensions of x.
If levels[[i]] is NULL no column is produced for this factor.
If levels[[i]] is NA, the result column is a numeric with range from 1 to dim (x)[i]
names(levels) yield the resulting column names.
matrix If TRUE, a numeric matrix rather than a data.frame is returned.
label.x Name for the column containing the x values.

Details

If the resulting data.frame is too large to fit in memory, a matrix might help.

The main benefit of this function is that it uses matrices as long as possible. This can give large advantages in terms of memory consumption.

Value

A data.frame or matrix with prod (dim (x)) rows and length (dim (x)) + 1 columns.

Author(s)

C. Beleites

See Also

stack

Examples

arr <- array (rnorm (24), 2:4)

array2df (arr)

array2df (arr, levels = list(NULL, x = NA, c = NULL), label.x = "value")

array2df (arr, levels = list(NULL, x = NA, c = letters [1:4]), label.x = "value")

summary (array2df (arr,
                   levels = list(NULL, x = NA, c = letters [1:4]),
                   label.x = "value"))

summary (array2df (arr,
                   levels = list(NULL, x = NA, c = letters [1:4]),
                   label.x = "value",
                   matrix = TRUE))


[Package hyperSpec version 0.95 Index]