Get startedGet started for free

Indexing commands in xts

1. Indexing commands in xts

Recall that xts objects are ordered by a universal time-based index.

2. Extracting the index

One useful trick in xts is to directly access this index using the .index() command, which returns the underlying time values stored by xts in the form of fractional seconds since the Unix epoch. While these values aren't directly useful, extensions of this command can be used to access other useful pieces of information.

3. Weekday observations

For example, the .indexwday() command gives you the weekday of each observation, with 0 equal to Sunday, 1 equal to Monday, 2 equal to Tuesday, and so on. In sports data, this command allows you to isolate games occurring on a particular day of the week. More generally, this allows you to isolate financial transactions happening at different points in the week or to explore patterns in user behavior on certain days.

4. Let's practice!

In the final set of exercises, you'll practice these indexing and subsetting commands using additional data on Boston sports teams. You should also take the opportunity to explore this final set of time series data to practice whatever commands you'd like.