CommencerCommencer gratuitement

Derive employee tenure

In this exercise, you'll derive employee tenure within the organization, i.e., the length of time an employee worked/has been in the organization.

In order to find the time difference between two dates, you can use the interval() and time_length() functions from lubridate. We have already converted the relevant date columns from character to date format.

Remember cutoff_date is used to calculate the tenure of Active employees while last_working_date is used for Inactive employees.

Cet exercice fait partie du cours

HR Analytics: Predicting Employee Churn in R

Afficher le cours

Instructions

  • Derive tenure of employees in years using last_working_date, date_of_joining and cutoff_date.
  • Generate a box plot to visualize employee tenure for Active and Inactive employees.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Add tenure
emp_tenure <- emp_jhi %>%
  mutate(tenure = ifelse(status == "Active", 
                         time_length(interval(date_of_joining, ___), 
                                     "years"), 
                         ___(___(date_of_joining, ___), 
                                     "years")))

# Compare tenure of active and inactive employees
ggplot(emp_tenure, aes(x = ___, y = ___)) + 
  geom_boxplot()
Modifier et exécuter le code