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).
datePad(
mydata,
type = NULL,
interval = NULL,
start.date = NULL,
end.date = NULL,
fill = FALSE,
print.int = FALSE,
...
)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).
Data.frame or tibble containing at least a 'date' column (Date or POSIXt).
NULL or character vector of column names to group by.
NULL or character string describing target interval (e.g.
"1 min", "1 hour"). If NULL, the native interval is used.
Optional start date/time. If NULL, the group's minimum
date is used.
Optional end date/time. If NULL, the group's maximum date
is used.
Logical; when TRUE performs block-based filling described
above. When FALSE just completes the sequence leaving NA values.
Logical; when TRUE prints detected/selected interval
messages.
Passed to cutData() for use with type.
The function detects the native input interval automatically if interval is
not supplied, supports grouping via type, and preserves timezones for
POSIXt date columns.
df <- mydata[-c(2, 4, 7), ] # Remove some rows to create gaps
datePad(df)
Run the code above in your browser using DataLab