[R] aggregate months to years

From: Oehler, Friderike (AGPP) <Friderike.Oehler_at_fao.org>
Date: Mon, 14 Jul 2008 14:37:36 +0200

Many thanks for the recent answers to my question about pattern recognition. The hint to "grep" and the "pattern" argument brought me a big deal forward.

# Now, I have a data frame:

DATE <- c("1930-01-01", "1930-01-01", "1930-02-01", "1931-01-01", "1931-02-01", "1931-03-01") # almost all months until "1999-12-01". Day is always 01, the same months actually occur several times. FREQ <- rep(1,6)
ex<- data.frame(DATE,FREQ)

# I can aggregate it like this:

ex <- tapply(ex$FREQ, ex$DATE, sum)

# or use"grep" to extract a single year:
# ex[grep(pattern="^1931", ex$DATE),]

# But how can I aggregate the years such that a barplot would show me the
FREQ per year and not per month?


# Sorry for the bad example, of course my data.frame is much bigger and the
barplot gives me a nice monthly time series of events, but I really only want the occurrences per year, not per month.

Grateful for your advice!

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 Mon 14 Jul 2008 - 12:47:22 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 Mon 14 Jul 2008 - 14:31:41 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