Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Manipulating Time Series Data in R

Cursus bekijken

Oefeninstructies

  • Create a vector of window widths from card_price and assign it to price_windows.
  • Using price_windows, create an expanding mean of the card_price time series; assign it to price_exp_mean.
  • Add a ggplot2 line plot to card_price_plot by completing the statement; color the expanding window with a blue line.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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 = ___, ___)
Code bewerken en uitvoeren