Get startedGet started for free

Selecting a window from a time series

Real-life time series datasets can span decades, as in the case of long-term climate and meteorological studies, financial records, or stock market data. By creating a window from a time series, you can hone in on a specific region of important data or exclude parts of the data that may not be necessary to consider.

In this exercise, you'll select a window from the dow_jones time series, containing real-world stocks information from the Dow Jones Industrial Average – the stock prices from 30 major companies based in the United States.

The dow_jones dataset and the ggplot2, zoo, and lubridate packages are available to you.

This exercise is part of the course

Manipulating Time Series Data in R

View Course

Exercise instructions

  • Create a window from the dow_jones dataset which starts on January 1, 2019, and ends on January 1, 2021; assign this to dow_jones_window.

  • Generate an autoplot for the original dow_jones dataset with the y-axis label "Price (USD)".

  • Generate an autoplot for the dow_jones_window dataset with the y-axis label "Price (USD)".

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create a window from dow_jones
___ <- ___

# Create an autoplot from the original dow_jones
autoplot(___) + 
  labs(___)

# Create an autoplot from dow_jones_window
autoplot(___) + 
  labs(___)
Edit and Run Code