Expanding mean
Expanding means, also called cumulative means, allow you to calculate the mean value of a time series up to each point. By doing so, you can follow how the mean of your time series changes with time.
In this exercise, you'll calculate an expanding mean of the card_price time series. Once you create the expanding mean, you'll plot it on top of an existing plot of the original time series, called card_price_plot, a ggplot object which has already been created for you.
Remember, expanding windows must be right-aligned.
card_price, card_price_plot, and the zoo and ggplot2 packages are available to you.
Este ejercicio forma parte del curso
Manipulating Time Series Data in R
Instrucciones del ejercicio
- Create a vector of window widths from
card_priceand assign it toprice_windows. - Using
price_windows, create an expanding mean of thecard_pricetime series; assign it toprice_exp_mean. - Add a
ggplot2line plot tocard_price_plotby completing the statement; color the expanding window with a blue line.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# 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 = ___, ___)