The input and its intended output show that I want to replicate the row of the input and update the date entry. How can I do this?
Input
> aa<- data.frame(a=c(1,11,111),b=c(2,22,222),length=c(3,5,1),date=c(as.Date("28.12.2016",format="%d.%m.%Y"), as.Date("30.12.2016",format="%d.%m.%Y"), as.Date("01.01.2017",format="%d.%m.%Y")))
> aa
a b length date
1 1 2 3 2016-12-28
2 11 22 5 2016-12-30
3 111 222 1 2017-01-01
Intended Output
a b length date
1 1 2 3 2016-12-28
2 1 2 3 2016-12-29
3 1 2 3 2016-12-30
4 11 22 5 2016-12-30
5 11 22 5 2016-12-31
6 11 22 5 2017-01-01
7 11 22 5 2017-01-02
8 11 22 5 2017-01-03
9 111 222 1 2017-01-01
You can use
base
,dplyr
, ordata.table
for the grouping operations. First repeat the rows to get the size of the new data correct. Then increment the days.For more concise syntax, we can take advantage of the recycling rules of data.table, credit @Henrik: