【发布时间】:2015-04-13 10:15:24
【问题描述】:
我在从 2004 年 7 月 9 日到 2014 年 12 月 31 日的十年期间的每日销售额 R 中有两个变量数据框 (df)。并非每个日期都以十年为单位表示,但几乎是周一到周五的大多数日子。
我的目标是按季度汇总销售额,转换为时间序列对象,并运行季节性分解和其他时间序列预测。
我在转换时遇到了问题,因为最终我收到了一个错误:
time series has no or less than 2 periods
这是我的代码结构。
# create a time series object
library(xts)
x <- xts(df$amount, df$date)
# create a time series object aggregated by quarter
q.x <- apply.quarterly(x, sum)
当我尝试运行时
fit <- stl(q.x, s.window = "periodic")
我收到错误消息
series is not periodic or has less than two periods
当我尝试运行时
q.x.components <- decompose(q.x)
# or
decompose(x)
我收到错误消息
time series has no or less than 2 periods
那么,我如何获取包含日期变量和金额变量(销售额)的原始数据框,将季度聚合为时间序列对象,然后运行时间序列分析?
【问题讨论】:
-
请提出您的问题easily reproducible。
-
创建 xts 对象时缺少“order.by”参数
标签: r time-series xts forecasting