Re: [R] Zoo series to a date time stamp that is regular

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Mon, 28 Jun 2010 18:05:41 -0400

On Mon, Jun 28, 2010 at 5:52 PM, stephen sefick <ssefick_at_gmail.com> wrote:
> Gabor,
> This is very close, but it interpolates values that do not exist in
> the original series.  Is there a way to just "snap" the series to a
> grid without interpolating?
>

Just round up or down the times with trunc. Using z from my prior post this rounds up to the next 10 minute boundary. (If there are multiple data values in a 10 minute interval it takes the last value.)

min10 <- times("00:10:00")
halfsec <- times("00:00:01")/2
aggregate(z, trunc(time(z) + as.numeric(min10 - halfsec), min10), function(x) tail(x, 1))

If there is only data value in each 10 minute interval this will round it up. If there are multiple data values in an interval it it takes the last one.



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 28 Jun 2010 - 22:09:00 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 Jun 2010 - 22:50:42 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive