For a financial model to be coded using the dplyr
package in R, I need to refer to lag
ged and lead
values of variables but I cannot seem to get the code for the lag
function working as documented.
> library(dplyr)
> x <- seq(100,500,100)
> x
[1] 100 200 300 400 500
> lead(x,1)
[1] 200 300 400 500 NA
> lag(x,1)
Error in lag(x, 1) : unused argument (1)
>
I was expecting lag(x,1)
to result in: NA 100 200 300 400
.
Any advice?Thanks.