Indexing commands in xts

Case Study: Analyzing City Time Series Data in R

Lore Dirick

Manager of Data Science Curriculum at Flatiron School

Extracting the index

  • .index() extracts raw time 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
Case Study: Analyzing City Time Series Data in R

Weekday observations

  • .indexwday() gives the weekday of each observation
.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 ...
  • Select only Sunday games
sunday_games <- which(.indexwday(sports) == 0)
Case Study: Analyzing City Time Series Data in R

Let's practice!

Case Study: Analyzing City Time Series Data in R

Preparing Video For Download...