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_dateSST
2008-01-01 22.
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 i
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
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
Using the zoo package:
Lines <- "SST_dateSST
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 = "
5 matches
Mail list logo