从第三季度开始,如何将时间序列中的季度数据转换为年度数据?
我试图首先将我的 CSV(excel)数据转换为时间序列,该时间序列分为几个季度,但从第 3 季度开始。然后,我尝试将数据聚合为每年,如下所示:
model_Tesla = ts(tesla_model$sales, start=c(2017,3), frequency=4)
tesla_annual=aggregate(model_Tesla, FUN=sum, nfrequency=1)
但是,当我运行它时,它的值年度数据全部错误。另外,它说新的 ts tesla_annual 于 2017.5 开始,于 2020.5 结束,但事实并非如此。它实际上于 2021 年第四季度结束。我该如何修复它?任何帮助将不胜感激。
I am trying to first convert my CSV (excel) data into time series which is split into quarters but starts on quarter 3. Then, I am trying to aggregate the data into yearly as follows:
model_Tesla = ts(tesla_model$sales, start=c(2017,3), frequency=4)
tesla_annual=aggregate(model_Tesla, FUN=sum, nfrequency=1)
However, when I run it the values for the annual data are all wrong. Also, it says the new ts tesla_annual starts on 2017.5 and ends on 2020.5 when that is not true. It actually ends in 2021 quarter 4. How can I fix it? Any help will be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您出于特定原因不需要
ts
,您可能会发现包{lubridate}
很有用。它提供了许多方便的包装器用于时间和日期操作。对于您的情况,以下代码可能会有所帮助:If you don't need
ts
for a particular reason, you might find package{lubridate}
useful. It offers a number of convenient wrappers for time and date manipulation. In your case, the following code might help along: