I want to add a dataframe column of integers to dataframe columns of dates in the same row, putting the result into new columns. Then count days from start to events in the same row, putting those into new columns. Have many date columns and many more than 5 rows in the dataframe, so a loop or something like that might be good.
This is what I have:
havedf <- data.frame(id = c("100","103","104","107","109"),
startDate = c("2015-04-02","2017-01-10","2016-02-11","2012-01-16","2014-03-05"),
eventOneDate = c("2015-04-10","2017-03-13","2016-03-04","2012-03-06","2014-03-11"),
eventTwoDate = c("2015-05-02","2017-08-12","2016-05-09","2012-04-05","2014-06-09"),
extradays = c(12,9,16,5,10))
This is what I want:
wantdf <- data.frame(id = c("100","103","104","107","109"),
startDate = c("2015-04-02","2017-01-10","2016-02-11","2012-01-16","2014-03-05"),
eventOneDate = c("2015-04-10","2017-03-13","2016-03-04","2012-03-06","2014-03-11"),
eventTwoDate = c("2015-05-02","2017-08-12","2016-05-09","2012-04-05","2014-06-09"),
extradays = c(12,9,16,5,10),
startDate_w_extra = c("2015-04-14","2017-01-19","2016-02-27","2012-01-21","2014-03-15"),
eventOneDate_w_extra = c("2015-04-22","2017-03-22","2016-03-20","2012-03-11","2014-03-21"),
eventTwoDate_w_extra = c("2015-05-14","2017-08-21","2016-05-25","2012-04-10","2014-06-19"),
daysToEventOne = c(8,62,22,50,6),
daysToEventTwo = c(30,214,88,80,96))