按列合并时间序列数据

案例研究:在 R 中分析城市时间序列数据

Lore Dirick

Manager of Data Science Curriculum at Flatiron School

合并前的准备

  • 检查周期性与覆盖范围
periodicity(temps_xts)
每日周期:2007-01-01 到 2015-12-31
periodicity(flights_xts)
每月周期:2010-01-01 到 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 中分析城市时间序列数据

Passons à la pratique !

案例研究:在 R 中分析城市时间序列数据

Preparing Video For Download...