Working with the date format
After we have converted each data attribute to the proper data type, we may determine that some attributes in employees
and salaries
are in the date format. Thus, we can calculate the number of years between the employees' date of birth and current year to estimate the age of each employee. Here, we will show you how to use some built-in date functions and the lubridate
package to manipulate date format data.
Getting ready
Refer to the previous recipe and convert each attribute of imported data into the correct data type. Also, you have to rename the columns of the employees
and salaries
datasets by following the steps from the Renaming the data variable recipe.
How to do it…
Perform the following steps to work with the date format in employees
and salaries
:
- We can add or subtract days on the date format attribute using the following:
> employees$hire_date + 30
- We can obtain time differences in days between
hire_date
andbirth_date
using the following...