Simple data frame:
X2 <- runif(20, -2, 2)
X1 <- c(1:20)
data <- cbind(X1, X2)
Would like to calculate a new column of data consisting of the average of five data points from X2, for the whole column; eg, this new column's first point is the average of the first five points from X2, point 2 is the average of the second five points, etc. New column should have four total values in this example. I'm guessing this is done with a function and an apply, but I have no idea how to proceed. Any help would be appreciated!