[R] mean over previous cells

Gabor Grothendieck ggrothendieck at gmail.com
Fri Feb 20 12:36:31 CET 2009


Using the zoo package:

Lines <- "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"

library(zoo)
# z <- read.zoo("myfile.dat", header = TRUE)
z <- read.zoo(textConnection(Lines), header = TRUE)

merge(z, avg3 = rollmean(z, 3, align = "right"))

See the three zoo vignettes (pdf documents) for more info on zoo.


On Fri, Feb 20, 2009 at 3:38 AM, clion <birte_2 at hotmail.com> wrote:
>
> 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