zoo::yearqtr
在金融與商業情境中最常見的「年度季」概念,在時間序列分析中非常重要。zoo 套件提供 yearqtr 類別,可同時儲存日期的年份與季度成分。
在這個練習中,你將使用每季的銷售資料 quarterly_data,以及觀測日期的索引 date_index_quarter,每筆觀測都發生於一年中的各季度(每 3 個月)。
上述資料集以及 ggplot2、zoo、lubridate 套件都已可使用。
本練習屬於課程
在 R 中操作時間序列資料
練習說明
將向量
date_index_quarter轉換為yearqtr類別,建立索引index_yearqtr。建立
quarterly_sales,其為zoo物件,資料來源為quarterly_data,索引則使用你剛建立的index_yearqtr。加上 x 軸標籤 "Quarter"、y 軸標籤 "Quarterly Sum ($100k)",以及標題 "Quarterly Sales Report"。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create a year-quarter index
___
# Create the quarterly_sales zoo object
___
# Autoplot with axis labels and a title
___