Skip to contents

This function creates time-lagged rows in a tibble using the 'time_column' as the reference point. The new rows are filled with NA values and have their time interval shifted by a specified lag duration.

Usage

create_time_lags(
  x,
  n_lag_range = c(1, 14),
  time_lag = lubridate::days(14),
  lag_amount_units = lubridate::days(1),
  relative_to_start = TRUE,
  time_column_name = "time_column"
)

Arguments

x

A tibble containing the original data.

n_lag_range

A numeric vector of length 2 defining the range of lag times.

time_lag

A duration object specifying the size of the time lag.

lag_amount_units

A duration object or a numeric in seconds that determines the unit for the 'lag_amount' column.

relative_to_start

A logical value indicating whether the lag should be relative to the start or the end of the input time interval.

time_column_name

Name of the time column in x.

Value

A tibble with the original data and additional time-lagged rows.

Examples

if (FALSE) { # \dontrun{
lagged_tibble <- create_time_lags(
  x = original_tibble,
  n_lag_range = c(1, 14),
  time_lag = lubridate::days(14),
  lag_amount_units = lubridate::days(1),
  relative_to_start = TRUE
)
} # }