Assuming we use zoo, we define a test series, z, and then aggregate it:

> library(zoo)
> z <- zooreg(1000:2000, start = as.Date("2000-01-01"))
> aggregate(z, as.numeric(format(time(z), "%Y")), mean)
  2000   2001   2002
1182.5 1548.0 1865.5

See:
  vignette("zoo")
  vignette("zoo-quickref")
  ?zooreg
  ?aggregate.zoo
for more info.

On Nov 17, 2007 7:51 AM, lucia <[EMAIL PROTECTED]> wrote:
> Hello,
> I'm very new to R, and so my question is simple.
>
> I have data record with 80 years of daily temperatures in one long
> string.  The dates are also recorded, in YYMMDD format.  I'd like to
> learn an elegant simple way to pull out the annual averages.
> (Obviously, every 4th year has 366 days.)
>
> I know I can set up a formal loop to create annual records and then
> average. But R seems to have such neat methods, is there some better
> way to do this?
>
> Lucia
>
>
>
>        [[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.
>

______________________________________________
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.

Reply via email to