shift | R Documentation |
lead function to shift by one (or more).
shift(x, shift_by = 1)
x |
a vector of values |
shift_by |
an integer of length 1, giving the number of positions to lead (positive) or lag (negative) by |
Lead and lag are useful for comparing values offset by a constant (e.g. the previous or next value)
Taken from: http://ctszkin.com/2012/03/11/generating-a-laglead-variables/
This function allows me to remove the dplyr::lead depends. Still suggest for vignettes though.
d<-data.frame(x=1:15) #generate lead variable d$df_lead2<-ggRandomForests:::shift(d$x,2) #generate lag variable d$df_lag2<-ggRandomForests:::shift(d$x,-2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.