LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Manipulating Time Series Data in R

Kurs anzeigen

Anleitung zur Übung

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

Interaktive Übung

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

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