Weather in Auckland

Working with Dates and Times in R

Charlotte Wickham

Instructor

akl_weather_daily.csv

date,max_temp,min_temp,mean_temp,mean_rh,events,cloud_cover
2007-9-1,60,51,56,75,NA,4
2007-9-2,60,53,56,82,Rain,4
2007-9-3,57,51,54,78,NA,6
2007-9-4,64,50,57,80,Rain,6
2007-9-5,53,48,50,90,Rain,7
Working with Dates and Times in R

akl_weather_hourly_2016.csv

year,month,mday,time,temperature,weather,conditions,events,humidity,date_utc
2016,1,1,00:00:00,68,Clear,Clear,NA,68,2015-12-31T11:00:00Z
2016,1,1,00:30:00,68,Clear,Clear,NA,68,2015-12-31T11:30:00Z
2016,1,1,01:00:00,68,Clear,Clear,NA,73,2015-12-31T12:00:00Z
2016,1,1,01:30:00,68,Clear,Clear,NA,68,2015-12-31T12:30:00Z
2016,1,1,02:00:00,68,Clear,Clear,NA,68,2015-12-31T13:00:00Z
Working with Dates and Times in R

make_date(year, month, day)

make_date(year = 2013, month = 2, day = 27)
"2013-02-27"

make_datetime(year, month, day, hour, min, sec) for datetimes

Working with Dates and Times in R

dplyr Review

  • mutate() - add new columns (or overwrite old ones)
  • filter() - subset rows
  • select() - subset columns
  • arrange() - order rows
  • summarise() - summarise rows
  • group_by() - useful in conjuction with summarise()
Working with Dates and Times in R

Pipe %>%

# Without the pipe: nested functions
summarise(group_by(filter(releases, major == 3), minor), n =  n())

# With pipe: more linear releases %>% filter(major == 3) %>% group_by(minor) %>% summarise(n = n())
Working with Dates and Times in R

Let's practice!

Working with Dates and Times in R

Preparing Video For Download...