Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201919

Consecutive/Rolling sums in a vector in R

$
0
0

Suppose in R I have the following vector :

[1 2 3 10 20 30]

How do I perform an operation whereby at each index 3 consecutive elements are summed, resulting in the following vector :

[6 15 33 60]

where the first element = 1+2+3, the second element = 2+3+10 etc...? Thanks


Viewing all articles
Browse latest Browse all 201919

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>