Date and time with lubridate
Dates and times have their formatting as the main characteristic to distinguish this type of data. A quick look at the variables where a YYYY-MM-DD number appears is enough to tell that it is a date object. However, as mentioned, computers calculate date and time based on seconds, so it is not difficult to see a dataset that brings a variable date or time as an integer number. In those cases, the solution is to recur to the data dictionary (document with the description of each variable) or to the dataset owner and align if that column should indeed be treated as a datetime object or a regular number. Later in this chapter, we will see this problem in action and how to solve it.
Before that, let’s set the base by learning some fundamental functions that will help us to parse datetime objects, splitting them into separate objects. Once again, I will ask you to go over the table from Figure 6.2 to get familiar with the logic of the lubridate
library...