I have a set of raster. I would like to apply a function from 2001-01-01 to 2002-12-31 then 2002-01-01 to 2003-12-31. (Two years each time). Is it possible with tapply function (I have something with a loop but it is quite slow).
rast_stack <- sapply(1:1826, function(i) rast(nrows=10, ncols=10, xmin=0, xmax=10, ymin=0, ymax=10))
rast_stack<-rast(rast_stack)
rast_stack[]<-rnorm(n=ncell(rast_stack))
terra::time(rast_stack)<-seq(as.Date("2001-01-01"),as.Date("2005-12-31"),by="day")
I would like something like :
res<-tapp(rast_stack,2yearsIndex,myfunction)