Session Ready
Exercise

Querying for dates

One of the most powerful aspects of working with time series in xts is the ability to quickly and efficiently specify dates and time ranges for subsetting.

Date ranges can be extracted from xts objects by simply specifying the period(s) you want using special character strings in your subset.

A["20090825"]       ## Aug 25, 2009
A["201203/201212"]  ## Mar to Dec 2012
A["/201601"]        ## Up to and including January 2016

For this exercise you will create a simple but very common query. Extract a range of dates using the ISO-8601 feature of xts. After successfully extracting a full year, you will then create a subset of your new object with specific start and end dates using this same notation.

Let's find some time!

Instructions
100 XP
  • Using xts-style time subsetting, select only the year 2016 from the x time series, and call this x_2016.
  • Using an explicit start and end date string, get all data from January 1, 2016 through March 22, 2016. Call this jan_march.
  • To ensure that you subset all 82 rows, use the length function.