I need to calculate the number of days elapsed between multiple dates in two ways and then output those results to new columns: i) number of days that has elapsed as compare
You can just add each column with the simple difftime and lagged diff calculations.
difftime
diff
DATA$FIRST <- c(0, with(DATA, difftime(DATE[2:length(DATE)],DATE[1], unit="days") ) ) DATA$BETWEEN <- c(0, with(DATA, diff(DATE[1:(length(DATE) - 1)], unit="days") ) ) identical(DATA, RESULTS) [1] TRUE