[R] Sliding Window Time Series Analysis - hourly rainfall

Jamie Ledingham jamie.ledingham at newcastle.ac.uk
Thu Jan 24 12:48:46 CET 2008

I have a time series of rainfall in a dataframe.  I would like to be
able to aggregate this using a sliding window approach- i.e. a new 24
hourly total is calculated for each hours rainfall.  I'm struggling to
understand how this might be achieved - currently I've tried looping a
sum function to re-calculate a new total at every stage of the loop.

for (inp[[9]] in 1:length(inp[[9]])){data.frame(x<-sum(inp[y:y+24,9]))}

where inp is the data frame object and [[9]] is the column containing
y is used to try and get the previous 24 hours total however in it's
current state it seems useless.

If anyone could give me some pointers i'd be very pleased, I'm a bit new
to the R language so any help appreciated.
Jamie Ledingham

More information about the R-help mailing list