Given
set.seed(171124)
buy.term <- function(n)
floor(rgamma(n, 5, 1))
terms <- matrix(buy.term(30), 10, 3)
colnames(terms) <- LETTERS[1:3]
init.buy <- c('2017-11-01', '2017-11-14', '2017-11-23')
terms
## A B C
## [1,] 3 5 6
## [2,] 4 1 4
## [3,] 11 8 4
## [4,] 4 5 3
## [5,] 3 1 2
## [6,] 2 3 7
## [7,] 1 2 5
## [8,] 3 3 7
## [9,] 1 4 4
## [10,] 8 3 8
Code
# to date format
init.dates <- init.buy %>% as.Date()
# add terms
ret <- terms %>% apply(2, cumsum) %>% t() + init.dates
# reshape back to matrix
ret <- append(init.dates, ret) %>%
as.character() %>%
matrix(nrow = 11, byrow = T)
# copy back ABC
colnames(ret) <- colnames(terms)
ret
## A B C
## [1,] "2017-11-01" "2017-11-14" "2017-11-23"
## [2,] "2017-11-04" "2017-11-19" "2017-11-29"
## [3,] "2017-11-08" "2017-11-20" "2017-12-03"
## [4,] "2017-11-19" "2017-11-28" "2017-12-07"
## [5,] "2017-11-23" "2017-12-03" "2017-12-10"
## [6,] "2017-11-26" "2017-12-04" "2017-12-12"
## [7,] "2017-11-28" "2017-12-07" "2017-12-19"
## [8,] "2017-11-29" "2017-12-09" "2017-12-24"
## [9,] "2017-12-02" "2017-12-12" "2017-12-31"
## [10,] "2017-12-03" "2017-12-16" "2018-01-04"
## [11,] "2017-12-11" "2017-12-19" "2018-01-12"