Learn R Programming

Rapi (version 1.0.6)

lag_df: lag_df

Description

The lag_df function creates additional columns based on a list of column names and lag sequences. This feature is beneficial for scenarios where you need varying lag selections for certain columns, allowing flexibility in specifying different lags for different columns or opting for no lag at all.

Usage

lag_df(df, laglist)

Value

tibble

Arguments

df

A data.frame or tibble.

laglist

A list of column names where each index corresponds to a column name and the associated value is the lag sequence.

Examples

Run this code
df <- data.frame(a = 1:15, b = 2:16)
tb <- lag_df(df, laglist = list(a = 1:5, b = 1:3))

Run the code above in your browser using DataLab