Is this what you want to do?
bsp <- data.frame(stringsAsFactors=FALSE,
date = c("01.01.15", "02.01.15", "03.01.15", "04.01.15",
"05.01.15", "06.01.15", "07.01.15", "08.01.15",
"09.01.15", "10.01.15", "11.01.15", "12.01.15", "13.01.15",
"14.01.15", "15.01.15", "16.01.15", "17.01.15", "18.01.15",
"19.01.15", "20.01.15"),
action_day = c(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
packet_output = c(10000, 3000, 5000, 1000, 1000, 5000, 4000, 3000, 1500,
800, 1000, 1200, 950, 700, 1000, 900, 800, 850, 1300,
1100)
)
library(dplyr)
bsp %>%
mutate(action_day = ifelse(action_day == 1 | lag(action_day, 1) == 1 | lag(action_day, 2) == 1,
1, 0)) %>%
filter(action_day == 1) %>%
summarise(packet_output = sum(packet_output))
#> packet_output
#> 1 30000
Created on 2019-05-16 by the reprex package (v0.2.1)
PD: This is the proper way of sharing a reprex