Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aggregate by week in R

Tags:

r

aggregate

zoo

In R I frequently aggregate daily data (in a zoo) by month, using something like this:

result <- aggregate(x, as.yearmon, "mean", na.rm=TRUE)

Is there a way that I can do this by week?

like image 476
Richard Herron Avatar asked Nov 29 '10 23:11

Richard Herron


1 Answers

The easiest thing to do is to use the apply.weekly function from xts.

> apply.weekly(zoo(1:10, as.Date("2010-01-01") + 1:10), mean)
2010-01-03 2010-01-10 2010-01-11 
         3         42         10
like image 174
Shane Avatar answered Sep 25 '22 18:09

Shane