whats the purpose of a, it seems to have zero information content, it just coincidentally happens to be as long as the AD object ?
you should probably omit it, the role it served in my first example was the indexes into AD to manipulate.
set.seed(42)
AD <- runif (800000)
ten2 <- purrr::map_dbl(seq_along(AD),
~{
sum(AD[.:(.+1)]) / 2
})
ten2[is.na(ten2)]<-0
#an alternative using slider to slide a 2-length window over AD and apply a function to it
library(slider)
ten3 <- slide_dbl(AD,
.after = 1
,.f = mean)
note that in the slider example ten3 differs from ten2 based on the differing treatment of the final value,
which in the first way, is NA mapped to 0 but in the second way, is the mean of the single number in the last position of AD