Hey guys I have a zoo object of daily observations for 30 years that Looks something like this:
date x
1971-11-01 145.234
1971-11-02 234.522
1971-11-03 423.32
1971-11-04 333.11
I would like to calculate means for the period November to April for the entire time series. So my desired result should look like this:
date x
11/1971-04/1972 642.43
11/1972-04/1973 142.53
11/1973-04/1974 642.39
11/1974-04/1975 424.75
11/1975-04/1976 185.34
Can somebody help me?
If your dates are truly daily such that November first appears every year, the following strategy will allow you to group the observations.
The first line uses a logical vector based on a regular expression to drop months May through October. The second line uses a regular expression to return a logical vector indicating whether the observation is November first. I cut off the first element of the vector using
tail
and added TRUE, to make sure the that the group count begins with 1.cumsum
is then used to create the group indicators.At this point, you can use
aggregate
, for example, to get the group mean:data