How can i get two rasters that gives the maximum value for each grid cells per year and also gives the dates on which that maximum value has occured. Below is the reproducible e
You can do
wmax <- stackApply(r.dt, indices = indices, fun=function(i,...) which.max(i))
to get the indices that refer to the Date vector
To get (integer) date representations, i.e., the number of days since 1970-01-01, you could do something like this, for each year
m2000 = data.frame(from=1:3, to=as.integer(Date_val)[1:3])
x <- subs(wmax[[1]], m2000)