开始使用免费开始使用

查找重叠的索引

当两个时间序列在相同时间点都有观测值,即具有相同的索引时,就称它们存在重叠(overlap)。

通过使用 %in% 运算符创建子集,可以从其中一个时间序列中过滤出重叠点,从而将两个数据集合并。

在本练习中,您将拿到两个时间序列 coffeecoffee_overlap,并移除它们之间重叠的元素。

数据集 coffeecoffee_overlap,以及 zoolubridate 包,已为您准备好。

本练习是课程的一部分

R 中的时间序列数据处理

查看课程

练习说明

  • 使用值匹配运算符 %in% 来确定 coffee_overlap 的索引与 coffee 的索引重叠的那些位置。

  • 使用方括号([, ])和取反运算符(!)提取不属于 overlapping_indexcoffee_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)
编辑并运行代码