開始使用免費開始

尋找重疊的索引

當兩個時間序列在相同的時間點都有觀測值,也就是索引相同時,就稱為彼此「重疊」。

利用 %in% 運算子建立子集,可以從其中一個時間序列中篩掉重疊的點,讓兩個資料集能夠合併。

在這個練習中,你會拿兩個時間序列 coffeecoffee_overlap,並移除其中重疊的元素。

coffeecoffee_overlap 資料集,以及 zoolubridate 套件,都已提供給你使用。

本練習屬於課程

在 R 中操作時間序列資料

檢視課程

練習說明

  • 使用值比對運算子 %in% 判定 coffee_overlap 的「索引」哪些與 coffee 的「索引」重疊。

  • 使用方括號([])與否定運算子(!)擷取「不」屬於 overlapping_indexcoffee_overlap 值。

  • coffee 時間序列與 coffee_subset 合併,並檢視合併後的 autoplot。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# 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)
編輯並執行程式碼