尋找重疊的索引
當兩個時間序列在相同的時間點都有觀測值,也就是索引相同時,就稱為彼此「重疊」。
利用 %in% 運算子建立子集,可以從其中一個時間序列中篩掉重疊的點,讓兩個資料集能夠合併。
在這個練習中,你會拿兩個時間序列 coffee 與 coffee_overlap,並移除其中重疊的元素。
coffee 與 coffee_overlap 資料集,以及 zoo 和 lubridate 套件,都已提供給你使用。
本練習屬於課程
在 R 中操作時間序列資料
練習說明
使用值比對運算子
%in%判定coffee_overlap的「索引」哪些與coffee的「索引」重疊。使用方括號(
[、])與否定運算子(!)擷取「不」屬於overlapping_index的coffee_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)