I am trying to find the cumulative sum of x=c(1,2,3,4,5) based on moving window of y=c(1,1,2,3,2). I tried the following code based on rollapply in zoo package:
rollapply(c(1,2,3,4,5),c(1,1,2,3,2),cumsum,align="right",partial=T)
My expected answer is 1,2,5,9,9 (because I am cumulating from the left side) but instead I get the below 4x3 table:
How can I correct the code to get the desired result?

I think you should use
suminstead ofcumsumand you can use
mapplyas well to achieve the same outputBenchmark
shows
rollapplyis not efficient asmapply