Previously I asked related to this question but I need more elegant and general way to solve this. I have data separated in groups and I want to sum some rows in range based on conditional. I prefer to use 'dplyr' to do this because it's more straight forward for me to understand. related to this question but