开始使用免费开始使用

zoo::yearmon

当按年份的月份和季度处理时间序列数据时,常常需要使用 zoo 包中的 yearmonyearqtr 类。这样,您就可以处理未知具体日期或无需具体日期的观测数据。

在本练习中,您将使用一个销售数据向量 monthly_data,以及一个观测日期索引 date_index_month,其每个观测都发生在每月的第 1 天。

上述数据集以及 ggplot2zoolubridate 包已为您准备好。

本练习是课程的一部分

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
___
编辑并运行代码