I have a column of start and stop dates, and I need to extract the latest (most recent) stop date in order to calculate duration. (earliest start date - latest stop date) Unfortunately, the dates in the last column are not necessarily the latest dates. So, I would have to go by row and compare the dates to figure out the latest date. The other caveat is that not all columns will have dates.
Here's an example column of dates:
pacman::p_load(tibble, lubridate)
start_1 <- as_tibble(sample(seq(ymd("1999/01/01"), ymd("2000/01/01"), by="day"), 5))
stop_1 <- as_tibble(sample(seq(ymd("2000/01/01"), ymd("2001/01/01"), by="day"), 5))
stop_2 <- as_tibble(c(ymd("2000/03/05"), ymd("2000/11/15"), ymd("2000/07/22"), ymd("2000/05/05"), NA))
stop_3 <- as_tibble(c(ymd("2000/12/12"), ymd("2000/02/09"), NA, NA, NA))
dat <- cbind(start_1, stop_1, stop_2, stop_3)
I really have no idea how to go about this, and would appreciate any help.
Thank you!