查找重叠的索引
当两个时间序列在相同时间点都有观测值,即具有相同的索引时,就称它们存在重叠(overlap)。
通过使用 %in% 运算符创建子集,可以从其中一个时间序列中过滤出重叠点,从而将两个数据集合并。
在本练习中,您将拿到两个时间序列 coffee 和 coffee_overlap,并移除它们之间重叠的元素。
数据集 coffee 和 coffee_overlap,以及 zoo 和 lubridate 包,已为您准备好。
本练习是课程的一部分
R 中的时间序列数据处理
练习说明
使用值匹配运算符
%in%来确定coffee_overlap的索引与coffee的索引重叠的那些位置。使用方括号(
[,])和取反运算符(!)提取不属于overlapping_index的coffee_overlap值。将
coffee时间序列与coffee_subset合并,并查看生成的自动绘图。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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)