ComenzarEmpieza gratis

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.

Este ejercicio forma parte del curso

HR Analytics: Predicting Employee Churn in R

Ver curso

Instrucciones del ejercicio

  • 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.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# 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()
Editar y ejecutar código