R can handle date
variables in several ways. There are built-in R functions available to process date
variables, and there are also some useful contributed packages available. The built-in R function as.Date()
can handle only dates but not time, whereas the chron
package, contributed by James and Hornik in 2008, can handle both date and time. However, it cannot work with time zones. Using the POSIXct
and POSIXlt
class objects, we can work with time zones. But there is another R
package, lubridate
, contributed by Grolemund and Wickham in 2011, that has a much more user friendly functionality to process date and time, with time zone support. In this section, we will see how we can easily process date and time using the lubridate
package, and compare it with built-in R functions.
Like other statistical software, R
also has a base date, and using that base date, R
internally stores date objects. In R, dates are stored as the number of days elapsed since January...