Read excel data in format code|year|month|daysx31| to make ts

#get|excel|data
library(gdata)
 dat<-read.xls("C:/All.xls",sheet=2);dat[dat==999]<-NA
 stdata<-function(sname,scode,dat,prm) #dat= df(scode|year|mon|X1:X31 )
 {
 require(zoo)
 stnobj<-dat[which(dat[,1]==scode),]|#subset
 vals<-c(t(as.matrix(stnobj[,4:34]))|)#values
 dates<-matrix(rep(1:31,dim(stnobj)[1]),dim(stnobj)[1],31,byrow=T)
 for(i|in|1:dim(stnobj)[1]){for(j|in|1:31){dates[i,j]<-paste(stnobj[i,2],stnobj[i,3],dates[i,j],sep="-")}}
 dates<-as.Date(c(t(dates)))
 idt<-which(!is.na(dates))
 dates<-dates[idt]
 vals<-vals[idt]
 stnobj.prec<-zoo(vals,dates)
 return(stnobj)
 }
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s