Try with complete()
from tidyr
:
library(dplyr)
library(tidyr)
#Code
new <- df1 %>%
mutate(date=as.Date(date)) %>%
complete(periodNumber,date=seq(min(date),max(date),by='1 day')) %>%
fill(value) %>% select(2,1,3)
Output:
# A tibble: 45 x 3
date periodNumber value
<date> <int> <int>
1 2020-02-02 0 50
2 2020-02-03 0 50
3 2020-02-04 0 50
4 2020-02-05 0 50
5 2020-02-06 0 50
6 2020-02-07 0 50
7 2020-02-08 0 50
8 2020-02-09 0 35
9 2020-02-10 0 35
10 2020-02-11 0 35
# ... with 35 more rows
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…