Georg Hoermann [mailto:[EMAIL PROTECTED] wrote:
> www.hydrology.uni-kiel.de/~schorsch/statistik/erle_stat.csv ...
contains a 10 year dataset.
> We often need cumulative *annual* sums (sunshine, precipitation), i.e.
the sum must reset to 0
> at the beginning of the year. I know of cumsum(), but I do not now how
to split the dataset
> automagically into annual pieces so I can cumsum() every year
separately.

Several replies have been given using tapply/aggregate/split; here is a
more primitive approach.
I do the cumsum once for the series, and call it "x".  Then I subtract
from x the value of x on 12/31
of the prior year:

R> y <- read.csv("erle_stat.csv", as.is=TRUE)
R> year <- substring(y$DATUM, 7)
R> x <- cumsum(y$Peff)
R> y$cumPeff <- x - c(0,x)[match(year, year)]

-- David Brahm ([EMAIL PROTECTED])

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to