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

From: stephen sefick <ssefick_at_gmail.com>
Date: Wed, 25 Jun 2008 21:57:16 -0400


#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.
Received on Thu 26 Jun 2008 - 02:00:52 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 - 03:31:27 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