Skip to content

aggregating specific parts in zoo index column to perform sliding average

3 messages · Gabor Grothendieck, knavero

#
Here's my code:

http://pastebin.com/0yRxEVtm

The important parts are uncommented and should be easy to find using the
link above. For the following line of code, I plan on looking for a way to
offset it up 7 rows so that the 15 minute timestamp would be considered the
"median" of the subset being averaged to find the mean: 

avgCool = aggregate(intCool, trunc(time(intCool), times("00:15:00")), mean)

Currently the issue is that, with the truncate function, it "truncates" but
really rounds down the time series values to the 15 minute time stamp
earlier in the series. For example, let's say we have one minute intervals
0:00, 0:01, 0:02,....,0:37. It takes 0:00 - 0:14 and replaces that with
0:00. Then it sees 0:15, and changes values from 0:15 - 0:29 to 0:15. In
effect, aggregating the values and creating subsets. 

What I want to do here is change 0:00 - 0:07 to 0:00, change 0:08 - 0:22 to
0:15, and change 0:23 - 0:37 to 0:30 in which 0:15 and 0:30 are the medians
of each subset. Anyway, I hope that makes sense. Any ideas on which function
will make this an easy job? Much thanks in advance.



--
View this message in context: http://r.789695.n4.nabble.com/aggregating-specific-parts-in-zoo-index-column-to-perform-sliding-average-tp4426798p4426798.html
Sent from the R help mailing list archive at Nabble.com.
#
On Mon, Feb 27, 2012 at 10:17 PM, knavero <knavero at gmail.com> wrote:
Add 7.5 minutes before truncating so if x is your times, e.g. x <-
times(0:15/(24 * 60)), then try this:

min15 <- times("00:15:00")
trunc(x + min15/2, min15)
#
Thanks Gabor. Answering all my noob questions haha. Interesting strategy to
adjust the input raw data as opposed to Excel where one offsets the output
data instead. I'll remember that.

--
View this message in context: http://r.789695.n4.nabble.com/aggregating-specific-parts-in-zoo-index-column-to-perform-sliding-average-tp4426798p4429257.html
Sent from the R help mailing list archive at Nabble.com.