Hello everyone.
I am having a bit of a hard time to write some logic in R.
I dont think it to be very difficult but I am simply stuck.
Your help is very much appreciated.
I want to calculate how long it takes until it goes from "issues" to either "production" or "canceled"
This is my sample df:
issues <- c("2021-05-10 01:23:32","2021-04-28 15:10:17","2021-02-28 09:27:13","2021-03-01 00:27:17","2021-04-05 22:12:18") %>% ymd_hms()
production <- c("2021-03-08 16:54:11","2021-04-28 09:57:42", NA,"2021-06-15 17:32:17","2021-04-21 06:31:10") %>% ymd_hms()
canceled <- c("2021-05-16 05:39:02","2021-05-12 14:24:46","2021-06-13 01:14:53", NA,"2021-04-21 16:31:07") %>% ymd_hms()
teste <- data.frame(issues, production,canceled) %>% as_tibble()
So the calculation I want to do is: (production OR canceled) - issues
Logic:
i) I have to pick the lowest date between production and canceled BUT whatever date is picked it has to have happened AFTER Issues.
For example.
on the 1st row, production happened before issue, so we should pick canceled.
on the last row, production happened after issues and before canceled, so we should pick production.
I wrote a use case when code but it didn't work.... I am a bit frustrated to be honest, so if you could help me I would really appreciate it.
Thank you everyone, let me know if something is not clear.
Cheers