I have a dataset of depth over time (a 2 month period). The minimum time interval between depths is less than 1-min and the maximum is several days. in R, I want to calculate a moving average of depth based on a 6-hour (or 12-hour) time window around each observation (not a window based on lagging/leading number of observations).
I have tried the zoo package, but I couldn't seem to get rollmean to work for me.
A small subset of my data is: https://www.dropbox.com/s/lhhrdgt2mxasc9v/fid57.depth.test1.csv
And in R it looks like:
> str(my.data)
'data.frame': 51 obs. of 2 variables:
$ DateTime: POSIXct, format: "2013-08-07 06:49:46" "2013-08-07 06:55:17" "2013-08-07" 07:06:52" "2013-08-07 07:23:43" ...
$ Depth : num 28.6 31.7 29 35.2 33 ...
>head(my.data)
DateTime "Depth"
2013-08-07 06:49:46 28.58
2013-08-07 06:55:17 31.7
2013-08-07 07:06:52 29.02
2013-08-07 07:23:43 35.18
2013-08-07 07:27:14 32.98
2013-08-07 08:20:21 55.84
> dput(head(my.data))
structure(list(DateTime = structure(c(1375883386, 1375883717,
1375884412, 1375885423, 1375885634, 1375888821), class = c("POSIXct",
"POSIXt"), tzone = ""), Depth = c(28.58, 31.7, 29.02, 35.18,
32.98, 55.84)), .Names = c("DateTime", "Depth"), row.names = c(8481L,
8483L, 8484L, 8485L, 8487L, 8495L), class = "data.frame")
Any suggestions would be much appreciated.
Thank you in advance!