以欄位合併時間序列資料

個案研究:在 R 中分析城市時間序列資料

Lore Dirick

Manager of Data Science Curriculum at Flatiron School

合併前準備

  • 檢查週期性與涵蓋範圍
periodicity(temps_xts)
Daily periodicity from 2007-01-01 to 2015-12-31
periodicity(flights_xts)
Monthly periodicity from 2010-01-01 to 2015-12-01  
個案研究:在 R 中分析城市時間序列資料

合併前準備

  • 篩選相同涵蓋範圍的資料
    temps_xts_2 <- temps_xts["2010/2015"]
    
  • 轉換週期性
    temps_monthly <- to.period(temps_xts_2, 
                               period = "months")
    
  • 注意:只能轉為較低頻率
個案研究:在 R 中分析城市時間序列資料

在 xts 中使用 merge()

  • merge() 的順序決定欄位順序
  • 列順序依時間索引排序
flights_temps <- merge(flights_xts, temps_monthly)

head(flights_temps)
           flights    temps
2010-01-01    8912 36.12903
2010-02-01    8418 37.71429
2010-03-01    9637 42.22581
2010-04-01    9363 51.26667
2010-05-01    9360 56.87097
2010-06-01    9502 63.56667
個案研究:在 R 中分析城市時間序列資料

一起來練習吧!

個案研究:在 R 中分析城市時間序列資料

Preparing Video For Download...