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”
Exercise instructions
Use the value matching operator
%in%
to determine the indices ofcoffee_overlap
that overlap with the indices ofcoffee
.Use square brackets (
[
,]
) and the negation operator (!
) to extract the values ofcoffee_overlap
which are not part ofoverlapping_index
.Combine the
coffee
time series withcoffee_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)