Summarize Daily Precipitation by 4 and 6 days

I have daily data in csv format and the data frame is below. I wanted to find the sum and maximum of four and six days. However, I tried the commands below. When I use tapply i get the error and when I applied the rollapply command the data is rolled for four and six days like stepping one day ahead.
Can you help on this?

library(hydroTSM)
data.frame(
        Year = c(1904L, 1904L, 1904L, 1904L, 1904L, 1904L, 1904L, 1904L, 1904L,
                 1904L, 1904L, 1904L, 1904L, 1904L, 1904L, 1904L, 1904L, 1904L,
                 1904L, 1904L, 1904L, 1904L, 1904L, 1904L, 1904L, 1904L, 1904L,
                 1904L, 1904L, 1904L, 1904L, 1904L, 1904L, 1904L, 1904L, 1904L,
                 1904L, 1904L, 1904L, 1904L, 1904L, 1904L, 1904L, 1904L, 1904L,
                 1904L, 1904L, 1904L, 1904L, 1904L),
       Month = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
                 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
                 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
                 2L, 2L, 2L, 2L),
         Day = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
                 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L,
                 27L, 28L, 29L, 30L, 31L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
                 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L),
        Rain = c(0, 0, 1, 1, 1, 1, 0, 2, 2, 0, 4, 0, 0, 5, 0, 0, 3, 0, 10, 4,
                 10, 7, 10, 11, 0, 1, 5, 0, 0, 2, 0, 0, 0, 5, 0, 0, 1, 6, 0, 3,
                 0, 1, 0, 0, 1, 0, 0, 0, 0, 0)
)

day4=tapply(b$Rain,b$Year,b$Month,b$Day, width=4,sum,na.rm=TRUE)
Error in match.fun(FUN) : 
  'b$Month' is not a function, character or symbol
day4=rollapply(Rain,width=4, FUN=sum)
day4max=tapply(b$Rain,b$Year,b$Month,b$Day,width=4,max,na.rm=TRUE)
day4=rollapply(Rain,width=4, FUN=max)
1 Like