Get startedGet started for free

Advanced features of xts

1. Advanced features of xts

As you've discovered throughout this course, time series data manipulation often involves deriving new measures and indicators from your existing data. To do so, you’ll want to take advantage of some advanced features of xts. Two important features are identifying period endpoints and applying functions over a period.

2. Finding endpoints

Finding endpoints in your data requires you to specify the relevant period using the endpoints() command with your xts object. This command indexes the last observation per period you specify. For example, if you want to isolate year-end unemployment, you can use endpoints() to generate an index of the final measure of unemployment per year.

3. Apply by period

A second useful feature of xts is the period.apply() command, which allows you to extend regular apply functions over time. Returning to our unemployment data, we can calculate a yearly average by applying the mean function and specifying the years index generated using endpoints(). This produces a vector of average unemployment for each year in our data.

4. Sports data

In this chapter, you'll explore some time series data involving Boston-area sports teams. You've been given data on the score of each game involving a Boston team from 2010 through 2015, but you're really interested in determining who won each game and, ultimately, how trends in sports performance might influence Boston's tourism industry. Before you can conduct any time series analysis, you'll need to generate some new indicators from the data.

5. Let's practice!

OK, let's get to work!