maybe something like this:

dat <- data.frame(years=rep(1994:2004, each=10), x=rnorm(110), y=rnorm(110))
lapply(split(dat[,-1], dat$years), cumsum)


is what you want.

I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
    http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm


----- Original Message ----- From: "Georg Hoermann" <[EMAIL PROTECTED]>
To: <r-help@stat.math.ethz.ch>
Sent: Thursday, February 10, 2005 11:01 AM
Subject: [R] Annual cumulative sums from time series



Hello world,

I am actually transferring a course in data management for
students in biology, geography and agriculture
from statistica to R - it works
surprisingly well. If anyone is interested in my scratch/notepad
(in German language), please see

www.hydrology.uni-kiel.de/~schorsch/statistik/statistik_datenauswertung.pdf

(pages 40-52)

The dataset is:

www.hydrology.uni-kiel.de/~schorsch/statistik/erle_stat.csv

It contains a 10 year dataset. So far for introduction, now
comes the problem:

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.
I have the strong hope that the solution is one of these
one-liners which leave the students with eyes wide open in surprise and
makes them true believers in the power of the command-line 8-).


Thanks & Greetings
Georg


-- Georg Hoermann, Luebeck, Germany Tel. 0451/47 70 32, 0172/431 57 15, Penguin #189476

______________________________________________
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



______________________________________________ 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