Session Ready
Exercise

Time Zones (and why you should care!)

One of the trickiest parts to working with time series in general is dealing with time zones. xts provides a simple way to leverage time zones on a per-series basis. While R provides time zone support in native classes POSIXct and POSIXlt, xts extends this power to the entire object, allowing you to have multiple time zones across various objects.

Some internal operation system functions require a time zone to do date math. If a time zone isn't explicitly set, one is chosen for you! Be careful to always set a time zone in your environment to prevent errors when working with dates and times.

xts provides the function tzone(), which allows you to extract or set time zones.

tzone(x) <- "Time_Zone"

In this exercise you will work with an object called times to practice constructing your own xts objects with custom time zones.

Instructions
100 XP
  • Construct an xts time series of the numbers 1 through 10 called times_xts, with tzone set to "America/Chicago", and indexed by the times object.
  • Modify times_xts to show time in "Asia/Hong_Kong".
  • Extract the current time zone as a string.