在 xts 中索引命令

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

Lore Dirick

Manager of Data Science Curriculum at Flatiron School

提取索引

  • .index() 提取原始时间索引
.index(unemployment)
 [1] 189302400 191980800 194486400 197164800 
 [5] 199756800 202435200 205027200 207705600 
 [9] 210384000 212976000 215654400 218246400 
[13] 220924800 223603200 226022400 228700800
[17] 231292800 233971200 236563200 239241600
案例研究:在 R 中分析城市时间序列数据

按星期几的观测

  • .indexwday() 返回每个观测的星期几
.indexwday(sports)
 [1] 0 2 3 5 6 0 1 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 5 6 
[25] 0 1 2 3 4 5 6 0 1 2 3 5 6 0 1 2 3 4 5 6 0 1 2 3 
[49] 4 5 6 0 2 3 4 5 6 0 1 2 3 4 5 6 ...
  • 仅选择周日比赛
sunday_games <- which(.indexwday(sports) == 0)
案例研究:在 R 中分析城市时间序列数据

让我们练习!

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

Preparing Video For Download...