datePad: Pad a time-series dataframe and optionally fill values by...

View source: R/datePad.R

datePadR Documentation

Pad a time-series dataframe and optionally fill values by block

Description

Expand a dataframe that contains a 'date' column to a regular sequence of timestamps between specified start and end dates. The function can operate in two modes:

  • fill = FALSE: simply complete the sequence at the target interval.

  • fill = TRUE: regularise the data at the native interval to create explicit blocks, then expand to the target interval and carry the block's values forward so that intra-block timestamps inherit the block's measured value (block-filling behaviour).

Usage

datePad(
  mydata,
  type = NULL,
  interval = NULL,
  start.date = NULL,
  end.date = NULL,
  fill = FALSE,
  print.int = FALSE,
  ...
)

Arguments

mydata

Data.frame or tibble containing at least a 'date' column (Date or POSIXt).

type

NULL or character vector of column names to group by.

interval

NULL or character string describing target interval (e.g. "1 min", "1 hour"). If NULL, the native interval is used.

start.date

Optional start date/time. If NULL, the group's minimum date is used.

end.date

Optional end date/time. If NULL, the group's maximum date is used.

fill

Logical; when TRUE performs block-based filling described above. When FALSE just completes the sequence leaving NA values.

print.int

Logical; when TRUE prints detected/selected interval messages.

...

Passed to cutData() for use with type.

Details

The function detects the native input interval automatically if interval is not supplied, supports grouping via type, and preserves timezones for POSIXt date columns.

Value

A dataframe expanded to the requested sequence with values filled according to 'fill'. The returned object preserves the 'date' column type and timezone (for POSIXt).

Examples

df <- mydata[-c(2, 4, 7), ] # Remove some rows to create gaps
datePad(df)


openair documentation built on April 2, 2026, 9:07 a.m.