Handling strings and dates

Managing data containing dates can be challenging because of the various formats in which dates can be represented. Fixing issues in strings is generally less challenging because of the abundance of tools in R to handle and manipulate strings.

Fortunately, there is a very useful package in R called lubridate that is invaluable in terms of handling date objects.

There are two main classes of dates/times in R: POSIXct and POSIXlt. POSIX, which stands for portable operating system interface, defines POSIXct as the number of seconds since the Unix epoch, that is, 1970-01-01 00:00.00 UTC, and POSIXlt as the string representation of the same in the desired format.

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.