Padding data frame with missing dates, using year_month character variable (e.g. "2015-09")

Hi RStudio Community,

I usually pad my dataset to add rows with missing dates using the following script


dataset_new <- dataset_old
group_by(var1, var2, var3,var4, var5, var6, date_var)%>%
  summarise(event=sum(event)) %>%
  arrange(var1, var2, var3,var4, var5, var6, date_var) %>%
  group_by(var1, var2, var3,var4, var5, var6) %>%
  pad(start_val = ymd("2015-01-01")) %>% 
  fill_by_value(event, 0) %>%
  ungroup() %>%
  complete(var1, var2, var3,var4, var5, var6, date_var, fill = list(event= 0))

However, I'm working with a very large dataset, and I'm getting the following error code:

Instead of grouping by the date_var and padding the data based on this variable, can I use the pad() function to pad the data using a character date variable such as date_char== "2015-09". P.s. I would like to first aggregate the data by month, instead of the exact date, and use the pad function to add rows with missing months (instead of dates).

How to use the pad() function to insert rows with missing months based on the date_char variable instead of the date_var variable?

Thanks in advance!!

Hi @R_Inquirer,
Check out the padr:: thicken() function which can generate the month blocks from your data, and then use padr() to insert the missing ones.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.