time_pad: Function to pad time series.

View source: R/time_pad.R

time_padR Documentation

Function to pad time series.

Description

time_pad use is similar to openair's timeAverage, but the aggregation of values does not occur. time_pad does not drop non-numerical variables, can include identifiers post-pad, and can start and end a padded time-series at a "nice place", for example, at the beginning of an hour or day.

Usage

time_pad(df, interval = "hour", by = NA, round = NA, full = FALSE, warn = TRUE)

Arguments

df

A tibble/data frame including parsed dates. The date variable/column must be named date.

interval

Interval of returned time series. Some examples could be: "min" "hour", "day", "month", "year" but multiples such as "5 min" work too. interval can also be a numeric value such as 0.5 which is useful for sub-second padding.

by

Should time_pad apply the padding function to groups within df? This is helpful when there are many sites/other identifiers within df which need to be padded individually.

round

What date-unit should the first and last observations be rounded to? This allows the padded time-series to begin and end at a "nice place". Examples are "hour", "day", "month", and "year".

full

Should the date joining use the full_join function? If TRUE, no input dates will be lost but the default is FALSE.

warn

Should the function give a warning when dates are duplicated? Default is TRUE.

Details

time_pad pads a time series by calculating the maximum and minimum dates within a time series and then generating a uniform date sequence between the maximum and minimum dates. This date sequence is then joined to the input data frame and the missing values are represented as NA.

Value

Tibble.

Author(s)

Stuart K. Grange

See Also

See round_date_interval, timeAverage, round_date, left_join, aggregate_by_date

Examples


## Not run: 

# Pad time series so every minute is present
data_nelson_pad <- time_pad(data_nelson, interval = "min", round = "day")

# Keep identifying variables "site" and "sensor"
data_ozone_sensor_pad <- time_pad(
  data_ozone_sensor, 
  interval = "hour", 
  by = c("site", "sensor")
)


## End(Not run)


skgrange/threadr documentation built on May 11, 2024, 12:16 p.m.