I have below mentioned data frame:
Date Val1 Val2
2018-04-01 125 0.05
2018-04-03 458 2.99
2018-04-05 354 1.25
I want to add only missing dates considering Sys.Date()
(Here for example Sys.Date()
is 2018-04-06) in dataframe with corresponding val1 and val2 as 0.
I have tried:
t2<-merge(data.frame(Date= seq(min(ymd(t1$Date)), max(ymd(date)), by = "days")), t1, by = "Date", all = TRUE)
Required Dataframe:
Date Val1 Val2
2018-04-01 125 0.05
2018-04-02 0 0
2018-04-03 458 2.99
2018-04-04 0 0
2018-04-05 354 1.25
2018-04-06 0 0
See Question&Answers more detail:os