I have data that result as active and inactive. I need to compute the service length using different formulas due to different end dates. The data example as follow:
status joindate leftdate lengthOfservice
active 1/1/2020 <NA>
active 6/7/1999 <NA>
active 15/8/2015 <NA>
inactive 1/1/1984 <31/12/2009
I set the date as
library("lubridate")
Start <- as.Date(joindate)
End1 <- as.Date(30/4/2022) # an example of given date
End2 <- as.Date(leftdate)
I code as follow: *for inactive status
time_of_length <- interval(start, end2) %>%
as.numeric("years")
From this, i only have result for inactive person while Missing Value (NA) for active person.
I think the other one formula that should i use :
*for active
Time_of_length <- interval(start, end1) %>%
as.numeric("years")
However, i really did not know how to combined this. Im new to R. Thank you for your assistance.
Please assist me how can i solve the probelm. Is it using if else and to group_by them?