Function to extend data with date

Hi All,

Is there a function that can be used to extend data with date. For example, if data has monthly values till today and I want to fill in the numbers for same data but for future 1 year in months, is there a function that can extend the data?


I think your question is about forecasting

Anyway, heres a book

Thanks @nirgrahamuk !
In this case, we are not forecasting, but we are just trying to add some figures manually for next few months based on growth%. So, for following sample data, I am looking to extend the data for 2024 Year by month with empty Sales at the moment which we will fill manually.

df <- 
  stringsAsFactors = FALSE,
              Date = c("2023-01-01","2023-01-01",
           Country = c("CA","CA","US","US","CA",
              Type = c("A","B","A","B","A","B",
             Sales = c(460,470,480,490,500,510,

Do you mean something like this:


df <- data.frame("date"= as.Date(c("2023-09-01", "2022-08-30", "2021-07-15")))

df <- df %>%
  mutate(plus_year = date %m+% months (12))

df %>% flextable::flextable()



(new_part <- expand_grid(
  Date = seq.Date(
    from = as.Date("2024-01-01"),
    by = "1 month",
    length.out = 12
  distinct(df, Country, Type), Sales = NA

altogether <- bind_rows(
  df |> mutate(Date = as.Date(Date)),

Well! Actually, I was looking to extend data by rows. So, after 2023-12-01, I was looking for 2024-01-01, 2024, 02-01 and so on until 2024-12-01

Thanks @nirgrahamuk !
Yes, this is it!
Thanks a bunch!

This topic was automatically closed 7 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.