Advanced features of xts

Case Study: Analyzing City Time Series Data in R

Lore Dirick

Manager of Data Science Curriculum at Flatiron School

Finding endpoints

  • endpoints() indexes last observation per interval
years <- endpoints(unemployment, on = "years")

unemployment[years]
                us       ma 
Dec 1976  7.650000 8.200000
Dec 1977  6.400000 6.200000
Dec 1978  6.000000 5.700000
Dec 1979  6.000000 4.900000
Dec 1980  7.200000 5.100000
Case Study: Analyzing City Time Series Data in R

Apply by period

  • period.apply() extends apply functions to time
period.apply(unemployment, 
             INDEX = years, 
             FUN = mean)
               us       ma
Dec 1976 7.654167 9.633333
Dec 1977 7.016667 7.804167
Dec 1978 6.066667 6.220833
Dec 1979 5.945833 5.516667
Dec 1980 7.200000 5.629167
Case Study: Analyzing City Time Series Data in R

Sports data

  • Boston sports games, 2010 through 2015

$$

Boston Celtics and Boston Red Sox games

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...