I have a series of raster images with failed pixels and I want to replace these with a regressive time filter where the current day takes the value of the previous day, that is, the image i-3 incorporates the processing of i-2, i -2 the one from i-1 and so on up. My processing is a subset where if the current day has value 1 and the previous 3 take the value of 3. What I can not do is that the processing is carried out from i to i-n.
#Filtro temporal
library(raster)
library(MODIS)
library(rgdal)
setwd("D:/Estacional")
mypath9<-"D:/SNOWL"
myras9<-list.files(path=mypath9,pattern = glob2rx("*.tif$"),
full.names = TRUE, recursive = TRUE)
name9<-substr(myras9,16,28)
for (i in 363:93){
r<-raster(myras9[i])
r1<-raster(myras9[i-1])
r[(r1==3) & (r==1)]<-3
writeRaster(r,paste0("MOYDTF2",name9[i], sep=""),datatype='INT1U',format="GTiff",overwrite=TRUE)
}