as.dimension {data.cube} | R Documentation |
Build dimension
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, ...)
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. |
dimension class object.
dimension
, hierarchy
, level
, data.cube
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)