扩展均值
扩展均值(expanding mean),也称为累计均值,可用于计算时间序列在每个时间点"截至目前"的平均值。这样,您就能观察时间序列的均值如何随时间变化。
本练习中,您将计算 card_price 时间序列的扩展均值。创建扩展均值后,您会将其绘制在已有的原始时间序列图之上。该图名为 card_price_plot,是一个已为您准备好的 ggplot 对象。
请记住,扩展窗口必须使用 right 对齐。
card_price、card_price_plot,以及 zoo 和 ggplot2 包均已可用。
本练习是课程的一部分
R 中的时间序列数据处理
练习说明
- 从
card_price创建一个窗口宽度向量,并赋值给price_windows。 - 使用
price_windows为card_price时间序列创建扩展均值;将结果赋值给price_exp_mean。 - 通过补全语句,为
card_price_plot添加一个ggplot2折线图;使用蓝色线条表示扩展窗口。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create the vector of window widths
___
# Create the expanding window
___
# Plot the expanding window over the original time series
card_price_plot +
geom_line(data = ___, ___)