I need to create a column based on dates, this is my dataset:
test <- data.frame(PatientID = c("1000285","1000317", "1000399","10006485","10995700317" ), dateMI = c(NA, NA, "2008-10-26", "2008-10-26", NA),dateA = c(NA, NA,"2008-10-26", "2010-11-06", "2019-02-14"), dateCVA = c("2014-02-04", "2001-02-27", NA, NA, "2020-02-14"), stringsAsFactors = F)
I would need to create an extra column called dateEVENT
, that contains the most recent date from dateMI
, dateA
and dateCVA
.
So effectively the new dataset would look like the one below:
test <- data.frame(PatientID = c("1000285","1000317", "1000399","10006485","10995700317" ), dateMI = c(NA, NA, "2008-10-26", "2008-10-26", NA),dateA = c(NA, NA,"2008-10-26", "2010-11-06", "2019-02-14"), dateCVA = c("2014-02-04", "2001-02-27", NA, NA, "2020-02-14"), dateEVENT = c("2014-02-04", "2001-02-27", "2008-10-26", "2010-11-06", "2020-02-14"), stringsAsFactors = F)
What would be the best way of doing this?
thanks