[R] mean over previous cells

clion birte_2 at hotmail.com
Fri Feb 20 12:19:34 CET 2009


well, it "kind of works"
now, I get means from the 61st SST-value on (which is reasonable, so no
"carful discarding" of the first 60 values) but aswell I only get means
until the 186st SST-value (although I 've got about 4900 in total).  Allt
the rest is "NA" - besides the 60th value is "NaN"
Any idea, why it runs the loop only roughly 2 times then?

thanks,
birte


lauramorgana at bluewin.ch wrote:
> 
> Sorry, I meant:
> 
> 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-60: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.
> 
> ______________________________________________
> 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.
> 
> 

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




More information about the R-help mailing list