lag_of: Define a lagged feature from variable history

View source: R/derive.R

lag_ofR Documentation

Define a lagged feature from variable history

Description

Extract the k-th most recent value of a variable from sparse history as of (j, t).

Usage

lag_of(
  name,
  target,
  k = 1,
  lookback_t = NULL,
  lookback_j = NULL,
  include_current = FALSE,
  force = FALSE,
  na_value = NA,
  clock = "time"
)

Arguments

name

Name of the derived feature.

target

A target created by declare_variable().

k

Positive integer lag order (1 = most recent prior value by default).

lookback_t

Optional numeric lookback window on the time axis. Takes precedence over lookback_j.

lookback_j

Optional integer lookback window in event-index units.

include_current

Logical; include boundary event at t/j (default FALSE).

force

Logical; if TRUE return na_value when insufficient history exists (default FALSE).

na_value

Value to return when force=TRUE and insufficient history exists (default NA).

clock

Which column in entity$events defines the time axis for lookback_t (default "time").

Value

A function (entity, j, t) -> scalar or NULL.


fluxCore documentation built on Sept. 22, 2026, 5:07 p.m.