'how to create function in r to calculate sum of first 3 values of a column and repeatedly to i for the length of the column

vec <- c(3,5,3,4,3,9,1,8,2,5,7,8,9,10,11,12,13,25) i want to create a new column X for which first value will be 0, second value will be 0 and third value will be sum of first three value of column vec and it will be repeated through the length of vec. I am not able to create this function. Can anyone help me?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source