I need to calculate the number of days elapsed between several dates in two ways, and then output these results in new columns: i) the number of days elapsed compared to the first date (e.g., $ FIRST RESULTS) and ii) between successive dates (e.g. RESULTS $ BETWEEN). Here is an example with the desired results. Thanks in advance.
library(lubridate) DATA = data.frame(DATE = mdy(c("7/8/2013", "8/1/2013", "8/30/2013", "10/23/2013", "12/16/2013", "12/16/2015"))) RESULTS = data.frame(DATE = mdy(c("7/8/2013", "8/1/2013", "8/30/2013", "10/23/2013", "12/16/2013", "12/16/2015")), FIRST = c(0, 24, 53, 107, 161, 891), BETWEEN = c(0, 24, 29, 54, 54, 730))
source share