lagvariables: Lag variables in data nlags

Description Usage Arguments Details Value Examples

View source: R/variableencoding.R

Description

This function uses an existing dataset in the shape of a tibble and then lags each variable(column) in the tibble from 1 all the way up to nlag.

Usage

1
lagvariables(x, nlag = 5)

Arguments

x

the data tibble to operate on

nlag

the max number of lags to create for each variable

Details

This function requires that the first column in your tibble is called "date" and represents some kind of time epoch. Note also that you will get no NA's returned. This means that the returned data will start nlag-1 days later than the input data.

Value

a new tibble with the data lagged

Examples

1
2
3
4
5
6
7
8
library(dplyr)
tmpdf <- tibble(
  date = seq(from = as.Date("2018-01-01"), length.out = 10, by = "1 day"),
  a = 1:10, b = 11:20, d = 21:30
)
lagdf <- tmpdf %>% lagvariables(4)
lagdf
tmpdf

DoktorMike/datools documentation built on Feb. 28, 2021, 8:39 a.m.