Exercise

Class attributes - tclass, tzone, and tformat

xts objects are somewhat tricky when it comes to time. Internally, we have now seen that the index attribute is really a vector of numeric values corresponding to the seconds since the UNIX epoch (1970-01-01).

How these values are displayed on printing and how they are returned to the user when using the index() function is dependent on a few key internal attributes.

The information that controls this behavior can be viewed and even changed through a set of accessor functions detailed here:

  • The index class using indexClass() (e.g. from Date to chron)
  • The time zone using indexTZ() (e.g. from America/Chicago to Europe/London)
  • The time format to be displayed via indexFormat() (e.g. YYYY-MM-DD)

In this exercise, you will practice each of these functions and view the results of your changes. To do so, you'll once again use the temps data that has been pre-loaded into your workspace.

Instructions

100 XP
  • View the first three rows of the index in the current temps data.
  • Find the index class of temps using the most relevant command above.
  • Find the time zone of temps, again using the most relevant command above.
  • Change the index format of temps to "%b-%d-%Y".
  • View the new index format using head().