Hi- I am trying to create a date variable from two other date variables. Basically, I merged two separate datasets that both had a different named date variable, but I want to merge them into one variable that has either the non-missing date or the earlier date.
Here is an the minimally reproducible example:
MRE_date1 <- as.Date(c("2001-01-01", NA, "2002-01-01", "2003-01-01"))
MRE_date2 <- as.Date(c(NA, "2003-01-01", NA, "2001-01-01"))
MRE <- data.frame(MRE_date1, MRE_date2)
So, I want to create a new variable (MRE_finaldate) that is either the non-missing date or the earlier date. In this case MRE_finaldate would be: 2001-01-01, 2003-01-01, 2002-01-01, 2001-01-01. However, my working dataset is too large to do this manually. Does anyone know how I can produce a code that does this?