Get Started

Finding overlapping indices

Time series are said to overlap when there are observations in both time series with the same index, meaning they occur at the same point in time.

By creating a subset using the %in% operator, the overlapping points can be filtered out of one of the time series, allowing the two datasets to be combined.

In this exercise, you'll take two time series, coffee and coffee_overlap, and remove the elements that overlap.

The datasets coffee and coffee_overlap, as well as the zoo and lubridate packages, are available to you already.

This is a part of the course

“Manipulating Time Series Data in R”

View Course

Exercise instructions

  • Use the value matching operator %in% to determine the indices of coffee_overlap that overlap with the indices of coffee.

  • Use square brackets ([, ]) and the negation operator (!) to extract the values of coffee_overlap which are not part of overlapping_index.

  • Combine the coffee time series with coffee_subset and view the resulting autoplot.

Hands-on interactive exercise

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

# Determine the overlapping indexes
overlapping_index <-
  ___ %in% ___

# Create a subset of the elements which do not overlap
coffee_subset <- ___[___]

# Combine the coffee time series and the new subset
coffee_combined <- ___

autoplot(coffee_combined)
Edit and Run Code