I know how to take the lagged difference:
delX = diff(x)
But the only way I know to take the lagged sum is:
sumY = apply(embed(c(0,y),2),1, sum)
Is there a function that can take the lagged sum? This way (or sliding the index in some other fashion) is not very intuitive.
Matthew Plourde :
You're looking for filter:\n\nx <- 1:10\nfilter(x, filter=c(1,1), sides=1)\n# [1] NA 3 5 7 9 11 13 15 17 19\n\n\nYou could also use head and tail:\n\nhead(x, -1) + tail(x, -1)\n# [1] 3 5 7 9 11 13 15 17 19\n",
2015-12-02T16:36:00