Skip to content
Prev 366895 / 398502 Next

Challenge extracting months

Hi Kwesi,
I worked through your code below, and I think that when you have the
two variables "mon.t1" and "seas.t1" you can select a "rolling
quarter" like this:

# the file name in your example is different from the one you sent
era<-read.table(file="SAfr_700hpa_7x5II.txt",header=FALSE,sep=" ",
 skip=1,dec = ".")
era.nodes<-paste(era[,1],era[,2],sep=".")
era.nodes<-as.numeric(era.nodes)
era.nodes.days<-zooreg(era.nodes,start=as.Date("1980-01-01"),
 end=as.Date("2016-12-31"))
era.nodes.days.t1<-window(era.nodes.days,start=as.Date("1980-01-01"),
 end=as.Date("2016-12-31"))
mon.t1<-as.numeric(format(index(era.nodes.days.t1),"%m"))
addyear<-0
# this loop transforms mon.t1 into an increasing sequence of months
for(i in 2:length(mon.t1)) {
 if(seas.t1[i] > seas.t1[i-1]) addyear<-addyear+12
 mon.t1[i]<-mon.t1[i] + addyear
}
for(i in 1:(max(mon.t1)-2)) {
 # this gives a logical index for the rolling quarter
 rq<-mon.t1 %in% i:(i+2)
}

Each successive "rq" produced by the last loop can be used to extract
whatever values you want from "era" or "era.nodes".

Jim
On Tue, Jan 31, 2017 at 9:04 PM, Kwesi Quagraine <starskykwesi at gmail.com> wrote: