[1] NA
STAT1003 – Statistical Techniques
Dr. Emi Tanaka
Australian National University
These slides are best viewed on a modern browser like Google Chrome on a desktop or laptop. Some interactive components may require some time to fully load.
Date 📅 even though it looks like character 🔢1st January 1970 is a special reference point
Let’s have a look at the numerical value under the hood of Date objects
Yup, the number under the hood is the number of days after (if positive) or before (if negative) 1st January 1970
And yes, you can use as.Date to convert objects to Date
You can find some widely used conversion specification in documentation at
?strptime but some depends on your operating system
Below are some common ones:
%b abbreviated month%B full month%e day of the month (01, 02, …, 31)%d day of the month (1, 2, …, 31)%y year without century (00-99)%Y year with century, e.g. 1999POSIXctR has two main date-time classes in R: POSIXct and POSIXlt (avoid using POSIXlt if possible)
POSIX stands for Portable Operating System Interface
ct stands for calendar time
POSIXltPOSIXlt seems like it’s the same as POSIXctOlsonNames()lubridateDate, you can use ymd and friends. E.g.You might have guessed it but:
y = year, m = month, and d = day.The order determines the expected order of its appearance in the string
lubridatePOSIXct, you can use ymd_hms and friendsy = year, m = month, and d = dayh = hour, m = minute, and s = second.It’s remarkably clever!
The time has to be after date though.
lubridateMaking Date from individual date components:
Making POSIXct from individual components:
lubridateDuration is a special class in lubridateDuration are:Period is a special class in lubridatePeriod are like for Duration but without the prefix “d”:lubridate cheatsheet


STAT1003 – Statistical Techniques