
Hello R users,

I'm a newby to R (and programming software at large) and I would need some help to sum up event data at discreet time and irregular time interval into a hourly frequency.

Here is an example of my time series frame (irregular time-serie object - irts in the tseries package):

time                        value
2008-12-19 19:11:03 GMT    1
2008-12-19 19:12:00 GMT     0
2008-12-19 19:42:39 GMT     1
2008-12-19 20:42:41 GMT     1
2008-12-19 20:42:45 GMT     1
2008-12-19 20:42:48 GMT     1
2008-12-19 20:42:55 GMT     1
2008-12-19 20:42:57 GMT     1
2008-12-19 20:43:07 GMT     1
2008-12-19 20:43:16 GMT     1
2008-12-19 21:05:45 GMT     1
2008-12-19 21:07:58 GMT     1
2008-12-19 22:08:00 GMT     1
2008-12-19 22:08:33 GMT     1
2008-12-19 23:09:58 GMT     1
2008-12-19 23:10:32 GMT     1
2008-12-19 23:13:00 GMT     0
2008-12-19 23:14:29 GMT     1
2008-12-19 23:14:32 GMT     1
2008-12-19 23:14:35 GMT     1
2008-12-19 23:30:35 GMT     1
2008-12-19 23:38:56 GMT     1
2008-12-19 23:44:00 GMT     0
2008-12-19 23:45:00 GMT     0
2008-12-20 00:46:00 GMT     1
[...]
2009-05-13 13:45:36 GMT    1

And i'm trying to obtain a regularly spaced time series object which would aggregates the events (value ==1) occuring 30 minutes before and after every hour into a hourly rate, a little bite like this:

time                        value
2008-12-19 18:00:00 GMT    0
2008-12-19 19:00:00 GMT     1
2008-12-19 20:00:00 GMT     1
2008-12-19 21:00:00 GMT     9
2008-12-19 22:00:00 GMT     2
2008-12-19 23:00:00 GMT     5
2008-12-20 00:00:00 GMT     2
2008-12-20 01:00:00 GMT    1
[...]
2009-05-13 13:00:00 GMT    0
2009-05-13 14:00:00 GMT    1

So far, I've created a regular ts object (destination object I guess) based on my irregular one:

Code example (not to be run): 
test.ts<-approx.irts(test.irts,seq(from=test.irts$time[1],
to=test.irts$time[length(test.irts$time)],by = "1 hour"),rule=2,method="linear")

Which creates the regular ts fine, but doesn't aggregate the events.

I've tried to mess around with the aggregate function - but I can't get the codes right to do what I want. Here are examples of unsuccessful attempts:

try = aggregate(test.irts$value, by= list(time=test.ts$time), FUN= mean)
ERROR MESS: Error in FUN(X[[1L]], ...) : arguments must have same length

try = aggregate.ts(test.irts$value,frequency(test.ts$time),nfrequency=1, ndeltat=1)
PROBLEM: gives me only one vector for my values (no time vector) but they are NOT aggregated by hour.

try = list(x=test.ts$time, y=aggregate.ts(test.irts$value, nfrequency=1))
PROBLEM: Gives 2 separate vectors :hourly time step and values - but again, values are not aggregated by hour.


I would appreciate any cue or help. Thank you




Mathieu Beaulieu, 
Soil, Water & Environment Laboratory
Institute for Resources, Environment and Sustainability
University of British-Columbia
429-2202 Main Mall,
Vancouver, BC,
V6T 1Z4
Canada
http://www.landfood.ubc.ca/swel/ 


_________________________________________________________________
Internet explorer 8 aide à protéger la vie privée.

	[[alternative HTML version deleted]]


