Aan de slagGa gratis aan de slag

Expanding sum

Especially in fields such as finance, business, marketing, and analytics, expanding sums (also known as cumulative sums) are an important method for keeping track of running totals, and how those totals change over time. By calculating an expanding sum, it's possible to see which time periods saw financial growth, or where sales remained stagnant.

In this exercise, you'll take the daily_house_sales time series, representing the houses sold each day by a particular real estate broker, and calculate an expanding sum.

Remember, expanding windows must be right-aligned.

daily_house_sales and the zoo and ggplot2 packages are loaded for you.

Deze oefening maakt deel uit van de cursus

Manipulating Time Series Data in R

Cursus bekijken

Oefeninstructies

  • Create a sequence of window widths from daily_house_sales and assign it to exp_window_width.
  • Using daily_house_sales and exp_window_width, create an expanding sum and assign it to sales_exp_sum.
  • Complete the ggplot() statement to plot sales_exp_sum using a red-colored line plot.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Create the vector of window widths
___ <- ___

# Create an expanding window
___ <- ___

# Plot the expanding window with a red line
ggplot(___) + 
  ___ + 
  scale_y_continuous() + 
  theme_light()
Code bewerken en uitvoeren