Hi guys Does anyone know if it is possible to index a zoo series by a sequence? For instance, with the following irregular zoo object, I can calculate the range of its time-based index:
> r <- range(index(l.zoo)) > r [1] "2009-06-15 01:44:20.802 GMT" "2009-06-15 16:54:24.124 GMT" If I just want to be able to extract the last 1 minutes worth of data, I would like to be able to do something like the following: > r.1min <-range(r[2]-60, r[2]) > r.1min [1] "2009-06-15 01:44:20.802 GMT" "2009-06-15 16:54:24.124 GMT" last.minute <- l.zoo[ index(l.zoo) %in% r.1min] This doesnt work, as it is doing a straight subset check (which is appropriate). So I am using the following method: last.minute <- l.zoo[ index(l.zoo) >= (r[2]-60)] is this the best way to do this (I suspect not)? -- Rory On Jun 16, 2009 2:52pm, rory.wins...@gmail.com wrote: > Thanks Gabor - I'll check it out. > Actually I just realised I can also do what I am looking for in a > ridiculously simple manner (as the data I have is intra-day): > aggregate(l.zoo, hours(index(l.zoo)), mean) > Cheers > -- Rory > On Jun 16, 2009 2:46pm, Gabor Grothendieck ggrothendi...@gmail.com> wrote: > > See R News 4/1. > > > > > > > > On Tue, Jun 16, 2009 at 9:04 AM, rory.wins...@gmail.com> wrote: > > > > > Hi all > > > > > > > > > > I have an irregular zoo series, where the time index looks like the > > > > > following: > > > > > > > > > >> head(time(l.zoo)) > > > > > > > > > > [1] "2009-06-15 01:44:20.802 GMT" "2009-06-15 01:44:20.812 > GMT" "2009-06-15 > > > > > 01:44:20.837 GMT" "2009-06-15 01:44:20.848 GMT" "2009-06-15 > 06:00:01.320 > > > > > GMT" > > > > > [6] "2009-06-15 06:00:01.330 GMT" > > > > > > > > > >> as.numeric(head(time(l.zoo))) > > > > > > > > > > [1] 1245030261 1245030261 1245030261 1245030261 1245045601 1245045601 > > > > > > > > > >> epoch + as.numeric(head(time(l.zoo))) > > > > > > > > > > [1] "2009-06-15 01:44:20.802 GMT" "2009-06-15 01:44:20.812 > GMT" "2009-06-15 > > > > > 01:44:20.837 GMT" "2009-06-15 01:44:20.848 GMT" "2009-06-15 > 06:00:01.320 > > > > > GMT" > > > > > [6] "2009-06-15 06:00:01.330 GMT" > > > > > > > > > > > > > > > What I would like to do is to run aggregate() over this zoo series, > and > > > > > compute a statistic over say a 5-minute or 1-hour interval. However, > I cant > > > > > seem to get chron() to figure out the right dates: > > > > > > > > > >> chron(as.numeric(head(time(l.zoo)))) > > > > > > > > > > [1] (01/28/47 19:14:53) (01/28/47 19:29:17) (01/28/47 20:05:17) > (01/28/47 > > > > > 20:21:07) (01/28/89 07:40:48) (01/28/89 07:55:12) > > > > > > > > > >> epoch > > > > > [1] "1970-01-01 GMT" > > > > > > > > > > > > > > >> chron(as.numeric(head(time(l.zoo))), origin.=epoch) > > > > > [1] (12/20/64 19:14:53) (12/20/64 19:29:17) (12/20/64 20:05:17) > (12/20/64 > > > > > 20:21:07) (12/22/06 07:40:48) (12/22/06 07:55:12) > > > > > > > > > > Does anyone know what I am doing wrong here? > > > > > > > > > > Cheers > > > > > -- Rory > > > > > > > > > > [[alternative HTML version deleted]] > > > > > > > > > > ______________________________________________ > > > > > R-help@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. > > > > > > > [[alternative HTML version deleted]] ______________________________________________ R-help@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.