推導員工年資
在這個練習中,你將推導組織內的員工年資,也就是員工在組織中工作/待著的時間長度。
要找出兩個日期之間的時間差,可以使用 lubridate 套件中的 interval() 與 time_length() 函式。我們已經把相關的日期欄位從字元轉換為日期格式。
記得,計算 Active 員工的 tenure 要使用 cutoff_date,而 Inactive 員工則使用 last_working_date。
本練習屬於課程
HR 分析:以 R 預測員工流失
練習說明
- 使用
last_working_date、date_of_joining與cutoff_date,以年為單位推導員工的tenure。 - 繪製盒狀圖來視覺化
Active與Inactive員工的年資分布。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# 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()