I have the raw data frame:
igroup=c(\"A\", \"B\", \"C\")
demo_df=data.frame(date=c(\"2018-11-28\", \"2018-12-17\", \"2019-01-23\"), group)
Raw
First, make sure date
is stored as a date object:
demo_df$date <- as.Date(demo_df$date, format = "%Y-%m-%d")
Then using tidyverse
, we first complete
the sequence, then fill
the group down:
library(tidyverse)
demo_df %>% complete(date = seq.Date(min(date), max(date), by = "day")) %>%
fill(igroup)