as.dimension: Build dimension

Description Usage Arguments Value See Also Examples

View source: R/as.dimension.R

Description

Build dimension

Usage

1
2
3
4
5
6
7
8
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)

jangorecki/data.cube documentation built on Aug. 22, 2019, 4:15 p.m.