我有一个时间序列数据框A Time Series: 6 × 12
,可以使用以下语法生成
library(hts)
ts(rnorm(67), start=c(2015, 4), frequency=12)
当我跑
aggregate(ts(rnorm(67), start=c(2015, 4), frequency=12), nfrequency=4)
它生成“时间序列:6 × 4”
但是,我想做的是创建层次结构:
例如:
Level 0: 2015
Level 1: Q1, Q2, Q3, Q4
Level 2: January, February, ....December
在哪里Q1= sum(January, February, March, April), Q2 = sum (next four months)
等。
当我跑步时
hts(ts(rnorm(67), start=c(2015, 4), frequency=12))
我明白了
Error: Argument y must be a multivariate time series.
Traceback:
1. hts(ts(rnorm(67), start = c(2015, 4), frequency = 12))
2. stop("Argument y must be a multivariate time series.", call. = FALSE)
所以我的目标是根据季度和月份获取年度数据的层次值,即
Level 0: Total for that year
Level 1: Q1, Q2, Q3, Q4
Level 2: January, February, ....December