calculate tenure by DOJ

i have a reproducible data frame

df <- data.frame(ID =c(864,121,582,300,765,56,571,819,923,789,438,987,30,446,369,445),
                 name= c("xab","Lan","mun","mmc","aaf","nnhu","njam","jiha","ntha","gydbt","hytb","kula","huta","vcge","bhsue","nudj"),
                 DOJ = c("9/5/2005","8/23/2006","3/30/2006","5/29/2009","12/29/2009","6/20/2005","10/2/2010","11/15/2003","3/3/2004","4/23/2004","7/28/2003","8/27/2004","6/14/2007","3/24/2007","9/29/2009","9/4/2007"))

I am trying to create a function which will ask a column name of DOJ like hire date == "DOJ"
then will mutate a new column and calculate tenure in that column.

also if the date of birth is give then mutate a new column for date of hire is greater than date of birth + 20.

i have tried using mondf and difftime but unable to create function for that.

output will be like

enter image description here

Use the lubridate or anytime packages for date arithmetic.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.