as.array.data.table {data.cube}R Documentation

Convert data.table to array

Description

Converts single measure of data.table into array dimensioned by columns provided as argument.

Usage

## S3 method for class 'data.table'
as.array(x, dimcols, measure, dimnames, ...)

Arguments

x

data.table

dimcols

character vector of key column for all dimensions, if named then names will be used as dimension names, example c(product = "prod_id", x = "x_id").

measure

character scalar column name of a measure, is automatically detected if it is the only data.table columns not in dimcols or names of dimnames.

dimnames

list of named dimension key values, the same as array dimnames argument. If missing then dimension key values will be computed from x data.table.

...

ignored

Value

An array, when using dimnames the length will be prod(sapply(dimnames, length)), when using dimcols only the length will be x[, prod(sapply(.SD, uniqueN)), .SDcols = dimcols].

Note

When using dimcols arg the function will extract dimension key values from x data.table. If you have unique values for each dimension on hand, you can use dimnames argument to skip potentially heavy task of extract dimensions, also combine with dimcols if you need remap column name to custom dimension name.


[Package data.cube version 0.4.0 Index]