A special note on dates and/or time

Parsing date-time values in any platform can be a tedious operation, not least because of the various formats in which dates and times can be written.

The lubridate package makes it easy for anyone to work with dates and times in R. In addition, data.table also includes several helpful functions in order to work with date and time values:

Install.packages("lubridate") 
library(lubridate) 
 

We can create a sample table with dates and times as follows:

 
tdate <- data.frame(dt=(as.POSIXct("2010-03-18 19:08:10 EDT")) + 1000000 * runif(1000,-100,100), value=sample(LETTERS,1000,T)) 
 
head(tdate) 
 
str(tdate) 

Note that the dt column is already defined as of class POSIXct. However, in general, when reading date times ...

Get Hands-On Data Science with R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.