zoo::yearmon
当按年份的月份和季度处理时间序列数据时,常常需要使用 zoo 包中的 yearmon 与 yearqtr 类。这样,您就可以处理未知具体日期或无需具体日期的观测数据。
在本练习中,您将使用一个销售数据向量 monthly_data,以及一个观测日期索引 date_index_month,其每个观测都发生在每月的第 1 天。
上述数据集以及 ggplot2、zoo 和 lubridate 包已为您准备好。
本练习是课程的一部分
R 中的时间序列数据处理
练习说明
将
date_index_month转换为yearmon类,并赋值给index_yearmon。使用
monthly_data的数值和index_yearmon索引创建一个zoo对象monthly_sales。使用
autoplot绘制monthly_sales,并设置x 轴标签为"Month"、y 轴标签为"Sales ($100k)",标题为"Corporate Sales Data"。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create a year-monthly index
___
# Create a zoo object from the year-month index and monthly data
___
# Autoplot with titles and axis labels
___