as.dimension {data.cube}R Documentation

Build dimension

Description

Build dimension

Usage

as.dimension(x, ...)

## Default S3 method:
as.dimension(x, id.vars, hierarchies = NULL, ...)

## S3 method for class 'data.table'
as.dimension(x, id.vars = key(x), hierarchies = NULL,
  ...)

Arguments

x

data.table or object with a as.data.table method, build dimension based on that dataset.

id.vars

character scalar of dimension primary key.

hierarchies

list of hierarchies of levels and their attributes.

...

arguments passed to methods.

Value

dimension class object.

See Also

dimension, hierarchy, level, data.cube

Examples

library(data.table)
time.dt = data.table(date = seq(as.Date("2015-01-01"), as.Date("2015-12-31"), by=1)
                     )[, c("month","quarter","year") := list(month(date), year(date), quarter(date))
                       ][, c("weekday","week") := list(weekdays(date), week(date))][]
hierarchies = list(
    "monthly" = list(
        "year" = character(),
        "quarter" = character(),
        "month" = character(),
        "date" = c("year","month")
    ),
    "weekly" = list(
        "year" = character(),
        "week" = character(),
        "weekday" = character(),
        "date" = c("year","week","weekday")
    )
)
time = as.dimension(
    x = time.dt,
    id.vars = "date",
    hierarchies = hierarchies
)
str(time)

[Package data.cube version 0.4.0 Index]