I am relatively new to R, and I have been struggling to find a method to calculate averages of each and every 66th observations along a column on a dataset containing 11830 observations and three variables (along three columns). Hence, the average of the 1st, 66th, 132nd, 198th...etcetera, and then again 2nd, 67th, 133rd, 199th and so on until we reach the 11830rd observation. I have been trying in various ways unsuccessfully. Any ideas will be much appreciated. Thanks Massimo
Asked
Active
Viewed 28 times
0
-
Have a look at `zoo` package. `rollapply` or `rollmean` is what you are looking for – Sotos Mar 02 '17 at 10:02
-
`i <- 1; ind <- c(i, i-1 + seq(from=66, to=11830, by=66)); mean(x[ind])` ... eventually loop for `i` – jogo Mar 02 '17 at 10:40
-
`sapply(seq_along(1:16), function(x) mean(dat[t(seq(0,11830,by=66)+x),2]))` with dat being your `data.frame`, values in the second column. – count Mar 02 '17 at 10:57
-
Thank you! I'll try them all – Massimo Mar 03 '17 at 15:00