vecshift | R Documentation |
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.
vecshift(x, d = 0)
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. |
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.
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
.
vecshift(1:10, 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.