Re: [R] How to turn Time Series daily values into weekly means (aggregate?)

From: jim holtman <jholtman_at_gmail.com>
Date: Wed, 25 Jun 2008 22:24:30 -0400

y.ts <- ts(y, frequency=7) # make data weekly aggregate(y.ts, FUN=mean)

to get your 15 minute readings into a day, this should work:

y.ts <- ts(y, frequency=96)
aggregate(y.ts, FUN=mean)

This is fine as long as everything is evenly spaced. It might be better if you had the time of the observation so that it would take care of missing data when doing the aggregation.

On Wed, Jun 25, 2008 at 9:57 PM, stephen sefick <ssefick_at_gmail.com> wrote:
> #this is a daily series of precipitation data. I would like to condense it
> into weekly means. How can I do this
> #as a side note I would like to do this same thing to two years worth of
> fifteen minute interval data and make it into
> #a series of daily averages (there are 96 readings per day)
> #is aggregate the right function? or...
>
> y <- c(1.23, 0, 0, 0, 0, 0, 0, 0, 0, 0.27, 0, 0.29, 0, 0, 0, 0.43,
> 0.2, 0, 0, 0.06, 0.05, 0.36, 0.06, 0, 0, 0, 0, 0.16, 0, 0, 0,
> 0.17, 0, 0.31, 0, 0, 0.01, 0, 0, 0, 0.19, 0, 0, 0, 0, 0, 0, 0.01,
> 0, 0.13, 0, 0.58, 0.07, 0, 1.48, 0.14, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0.03, 0, 0, 0, 0.39, 0, 0, 0, 0, 0, 0.12, 2.79, 0, 0,
> 0, 0, 0, 0, 0.01, 0, 0, 0, 0.19, 0, 0, 0, 0, 0, 0, 0.89, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, 0, 0.64, 0, 0, 0.31, 0, 0, 0, 0.31, 0, 0,
> 0, 0, 0, 0, 0, 0.08, 0.37, 0, 0.49, 0, 0, 0, 0, 0, 0, 0.49, 0,
> 0, 0, 0.15, 0, 0, 0, 0, 0, 0, 0.07, 0, 0, 0, 0, 0, 0, 0, 1.43,
> 0.02, 0, 0, 0, 0, 0, 0, 0, 0, 0.81, 1.9, 1.02, 0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0.35, 0.89, 0, 0.01, 0, 0, 0, 0, 0, 0, 0, 0.22,
> 0, 0, 0, 0, 0, 0, 0, 0.01, 0, 0, 0, 0, 0, 0, 0, 0.21, 0.12, 0.58,
> 0, 0, 0, 0, 0.28, 0.09, 0, 0, 0, 0, 0.3, 0, 0, 0, 0, 0, 0.5,
> 0, 0.59, 0, 0, 0, 0.01, 0, 0, 0.04, 1.4, 0, 0.6, 0, 2.06, 0,
> 0, 0, 0, 0, 0.39, 0, 0, 0, 1.06, 0, 0.26, 0, 0.01, 0, 0, 0, 0,
> 0, 1.17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.18, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0.02, 0, 0.05, 0, 0, 0.84, 0, 0, 0, 0, 0.04, 0.06,
> 0, 0, 0, 0, 0.46, 0, 0, 0, 0, 0.91, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0.32, 0, 0, 0, 0, 0, 0, 0, 1.29, 0.3, 0, 0, 0, 0.01, 0.61,
> 0.34, 0, 0, 0, 0, 0, 0, 0, 0.08, 0.1, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0.02, 0, 0, 0, 0, 0, 0, 0, 0.28, 2.65, 0, 0, 2.21, 0,
> 0, 0, 0, 0.06, 0.12, 0.16, 0, 0, 0, 0.52, 0, 0.34, 0.18, 0, 0,
> 0, 0, 0, 0, 0, 0.03, 0.01, 0.28, 0, 0, 0.44, 0.75, 0, 0, 0, 0,
> 0, 0.33, 0, 0, 0, 1.28, 0.03, 0, 0, 0, 0, 0, 0, 0.01, 0, 0, 0,
> 0.69, 0, 0, 0, 0, 0, 0, 0, 0.57, 0, 0, 0, 0.24, 0, 0, 0)
>
> y.ts <- ts(y, frequency=30)
> aggregate(y.ts, nf=7, FUN=mean)
>
> --
> Let's not spend our time and resources thinking about things that are so
> little or so large that all they really do for us is puff us up and make us
> feel like gods. We are mammals, and have not exhausted the annoying little
> problems of being mammals.
>
> -K. Mullis
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>

```--
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
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 Thu 26 Jun 2008 - 02:30:46 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 Thu 26 Jun 2008 - 04:31:04 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.