# set sliding window and step size
window <- 100000
step <- 100000 # this means non-overlapping
# generate left coordinates
left <- seq(1, (100*10^6), window)
# generate right coordinates
right <- left + (step-1)
# use sapply to estimate mean individual depth per window
sapply(1:length(left), function(z){
# create window
depth_window <- myData[myData$POS >= left[z] & myData$POS <= right[z], ]
# use apply to calculate individual means for window
ind_depth <- apply(depth_window[, 3:ncol(depth_window)], 2, function(y), mean, na.rm = TRUE)
# take mean of individual depths in window and return it
mean_ind_depth <- mean(ind_depth, na.rm = TRUE)
return(mean_ind_depth)
})