LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Manipulating Time Series Data in R

Kurs anzeigen

Anleitung zur Übung

  • 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.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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 bearbeiten und ausführen