6.1 Irregular time series

The most common class for time series is ts, but I prefer to work with xts since the latter handles irregular time series and has subsetting options not available for ts objects. You can convert strings (or numerical) to Date using as.Date. See ?DateTimeClasses for more information about the classes used to represent date and time objects.

library(xts)
library(lubridate)

6.1.1 Exercise 1: Jussy air temperature

  1. Load the data from the website, available at http://sma.epfl.ch/~lbelzile/math342/jussy_temp.csv, using the command
jussy <- read.csv("http://sma.epfl.ch/~lbelzile/math342/jussy_temp.csv", header = TRUE, 
    sep = ";", na.strings = "######", stringsAsFactors = FALSE)[, 1:2]
  1. Extract the time object and mutate the object to keep only the daily maximum (xts::apply.daily).
  2. Plot the daily maximum and comment on any particularity of the dataset (trend, seasonality, structural breaks, time window).
  3. Find how many days on average per year have temperature below zero.
  4. How many heatwaves have taken place during the data collection and how long did they last? For simplicity, define a heatwave as a period of more than 3 consecutive days during which the temperature exceeds 30C during the day, but does no down below 18C at night.