Are you looking for something like this?
x <- c(3,6,18,10,2) n <- length(x) sapply(seq_len(n-2), function(X) { mean(x[seq(X, n, by=2)]) })
And then something more interesting to earn @mnel upvote;)
n <- length(x) m <- matrix(0, n, n-2) ii <- row(m) - col(m) m[ii >= 0 & !ii %% 2] <- 1 colSums(x * m)/colSums(m)
source share