[R] mean over previous cells

lauramorgana at bluewin.ch lauramorgana at bluewin.ch
Fri Feb 20 10:23:41 CET 2009


If, suppose, the name of your dataframe is "dataframe" , you could try something like:
mean60days<-c()
for(i in 1:length(dataframe$SST))
+ {
+ mean60days[[i]]<-mean(dataframe$SST[i-10:i])
+ }
I'm not really sure it will work... my skills aren't that great...
Anyway, it worked on a sample I tried it on, but you have to be careful and discard the first 60 values!!
Hope it works,
ciao
Laura




Dear RUsers,
I guess this is an easy question for someone a little familiar with
programming...(which I am not)...

I've got 2 colummns, one shows just dates(SST_date, Class 'Date' num), the
other one shows the SeaSurfaceTemperature (SST, num) at that certain date.

SST_date    SST 
2008-01-01 22.2 
2008-01-02 21.8
2008-01-03 22.8
2008-01-04 22.9
2008-01-05 23.1
2008-01-06 23.2  
...
...

now, I would like to add a column that shows the mean SST over the last
(e.g.) 60 days (for that specific date).

My biological question is, whether the birthweight of an animal at a
specific birthdate changes due to the SST over the last 60 days before
birth. (SST is an indicator for food abundance - if food is scarce, mothers
can't feed much and hence, pups are born lighter!?)
Up to now, I can only show, whether the SeaSurfaceTemperatures on the
birthdate can have an influence on birthweight, which is not what I want to
do...

Can anybody tell me, how to start, where to look it up or help me even more? 
thanks in advance.
Birte

-- 
View this message in context: http://www.nabble.com/mean-over-previous-cells-tp22116807p22116807.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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.




More information about the R-help mailing list