I have daily rainfall data which I have converted to yearwise cumulative value using following code
library(tidyverse); library(segmented); library(seas); library(strucchange)
## get mscdata from "seas" packages
data(mscdata)
dat <- (mksub(mscdata, id=1108447))
## generate cumulative sum of rain by year
d2 <- dat %>% group_by(year) %>% mutate(rain_cs = cumsum(rain)) %>% ungroup
Then I want to compute of yearwise breakpoints using strucchange. I could able to do it for single year like
y <- subset(d2,year=="1992")$rain_cs
breakpoints(y ~ 1, breaks = 3)$breakpoints
I have used breaks = 3 to have 3 breakpoints. Now how to dynamically apply it year-wise to estimate breakpoints?