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 exercício faz parte do curso
HR Analytics: Predicting Employee Churn in R
Instruções do exercício
- Derive
tenureof employees in years usinglast_working_date,date_of_joiningandcutoff_date. - Generate a box plot to visualize employee tenure for
ActiveandInactiveemployees.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# 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()