擴展總和
在金融、商業、行銷與分析等領域,擴展總和(也稱為累積總和)是用來追蹤即時累計與其隨時間變化的關鍵方法。透過計算擴展總和,你可以看出哪些期間有成長,或在哪些地方銷售停滯。
在這個練習中,你將使用 daily_house_sales 這個時間序列(代表某位房仲每天賣出的房屋數量),並計算其擴展總和。
記得,擴展視窗必須是 right 對齊。
已為你載入 daily_house_sales,以及 zoo 與 ggplot2 套件。
本練習屬於課程
在 R 中操作時間序列資料
練習說明
- 從
daily_house_sales建立一個視窗寬度序列,指定給exp_window_width。 - 使用
daily_house_sales與exp_window_width建立擴展總和,指定給sales_exp_sum。 - 完成
ggplot()敘述,使用紅色折線圖繪製sales_exp_sum。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create the vector of window widths
___ <- ___
# Create an expanding window
___ <- ___
# Plot the expanding window with a red line
ggplot(___) +
___ +
scale_y_continuous() +
theme_light()