Suppose I have a data.frame, I wish to create a new column called duration, it is calculated only for records where status = Active, using 2016-12-10 as today's date, so that duration = today - start_date.
What's the best approach for this conditional calculation?
status <- c("Active", "Inactive", "Active")
date <- c("2016-10-25", "2015-05-11", "2015-3-18")
start_date <- as.Date(date, format = "%Y-%m-%d")
data.frame(status, start_date)