I have a column which has values in it. I want to create a second and third column that sums the previous 3 and 6 observations prior to that time period. Here's an example df:
x <- data.frame(Vessel = c(1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1)
Ideal outcome would look like this:
x <- data.frame(Vessel = c(1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0), minus3 = c(NA, NA, NA, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 0))