Session Ready
Exercise

Calculate time series trends

One of the most useful qualities of xts objects is the ability to conduct simple mathematical equations across time. In your flight data, one valuable metric to calculate would be the percentage of flights delayed, cancelled, or diverted each month.

In this exercise, you'll use your data to generate a new time series column containing the percentage of flights arriving late to Boston each month. You'll then generate a plot for this metric, before going on to calculate additional metrics for flight cancellations and diversions.

Instructions
100 XP
  • Use simple math expressions on flights_xts to calculate the percentage of flights delayed each month. Save this as a new column in flights_xts called pct_delay.
  • Use plot.xts() to view the percent of flights delayed each month.
  • Replicate your calculation above to produce two additional columns of data in your xts object -- pct_cancel and pct_divert -- for cancelled and diverted flights, respectively.
  • Use plot.zoo() to view all three trends together. To do so, you'll need to select a subset of the flights_xts data containing the three columns you just generated.