vecshift: Create lagged or lead variables

View source: R/ma.R

vecshiftR Documentation

Create lagged or lead variables

Description

This function replicates the functionality of the Stata subscript syntax (e.g. [_n-1]) to positionally shift a vector and create lagged or lead variables.

Usage

vecshift(x, d = 0)

Arguments

x

A vector (of any type)

d

How many places to shift. A positive integer means a shift to the left, a negative integer means a shift to the right.

Details

This function calculates the week number according to ISO 8601. Note that dates near the start or end of a given year may belong to the previous or next year respectively, thus the year needs to be calculated too.

Value

A vector of the same length as x, shifted d places to the left (if d positive) or right (if d negative). The rightmost or leftmost abs(d) place respectively are filled with NA.

Examples

vecshift(1:10, 3)


thlytras/Rivets documentation built on April 16, 2024, 5:43 a.m.