Skip to contents

Extend a time series with additional dates. This is useful when extending the report dates of a time series to include future dates for nowcasting purposes or to include additional dates for backcasting when using a renewal process as the expectation model.

Usage

enw_extend_date(
  metaobs,
  days = 20,
  direction = c("end", "start"),
  timestep = "day"
)

Arguments

metaobs

A data.frame with a date column.

days

Number of days to add to the time series. Defaults to 20.

direction

Should new dates be added at the beginning or end of the data. Default is "end" with "start" also available.

timestep

The timestep to used. This can be a string ("day", "week", "month") or a numeric whole number representing the number of days.

Value

A data.table with the same columns as metaobs but with additional rows for each date in the range of date to date + days

(or date - days if direction = "start"). An additional variable observed is added with a value of FALSE for all new dates and TRUE for all existing dates.

Examples

metaobs <- data.frame(date = as.Date("2021-01-01") + 0:4)
enw_extend_date(metaobs, days = 2)
#> Key: <.group, date>
#>          date .group observed
#>        <Date>  <num>   <lgcl>
#> 1: 2021-01-01      1     TRUE
#> 2: 2021-01-02      1     TRUE
#> 3: 2021-01-03      1     TRUE
#> 4: 2021-01-04      1     TRUE
#> 5: 2021-01-05      1     TRUE
#> 6: 2021-01-06      1    FALSE
#> 7: 2021-01-07      1    FALSE
enw_extend_date(metaobs, days = 2, direction = "start")
#> Key: <.group, date>
#>          date .group observed
#>        <Date>  <num>   <lgcl>
#> 1: 2020-12-30      1    FALSE
#> 2: 2020-12-31      1    FALSE
#> 3: 2021-01-01      1     TRUE
#> 4: 2021-01-02      1     TRUE
#> 5: 2021-01-03      1     TRUE
#> 6: 2021-01-04      1     TRUE
#> 7: 2021-01-05      1     TRUE