Hello,
Sorry if it's a simple question, this is my first script complex, but can
not find solution in the list

 I have many TXT files with daily data of meteorological stations and a
table that connects it with each of these stations. (More than one table per
station and date).

With the Script attempt:

 º1 Fit the data and create a regular series from  01.01.2000 to 12.31.2010
data for all tables by creating rows with null values ​​when is necessary to
facilitate further calculations

2 º From my table that relating data and stations obtaining the mean of the
results for each station.


The problem happens to me in the first step.

To optimize the script,

1, check year by year if I have 365 days. (If it´s true Is OK)

2 If not, check month after month.

3 ° For each time check if the number of existing data matches the number of
days in the month.

4 ° For cases that do not, add new rows to the table with these dates and null
value.

Well, the fact is that R skips the rule and not know that I am wrong. Can
you help?

Copy the script piece of Interest:

daysanyo<-c(31,28,31,30,31,30,31,31,30,31,30,31)
daysanyoBIS<-c(31,29,31,30,31,30,31,31,30,31,30,31)

addfilas<-function(table){
table$year=substr(table[[3]],1,4)
table$mes=substr(table[[3]],5,6)
table$day=substr(table[[3]],7,8)
table=subset(table,table$V3>="20000101" & table$V3<="20101231")
table$year<-as.numeric(table$year)
table$mes<-as.numeric(table$mes)
table$day<-as.numeric(table$day)


for (anyo in 2000:2010){
    table2=subset(table,table$year==anyo)
    ndias=length(table2$year)
         if(ndias<365){
              for (ms in 1:12){
                       table2=subset(table2,table2$mes==ms)
                        ndays=length(table2$year)
                          a<-(anyo==2000 | anyo==2004 | anyo==2008) &
(ndays<daysanyoBIS[ms])
                                      if(a==TRUE){
                                                  aa<-1:daysanyoBIS[ms]
                                                  bb<-aa

if(length(table2$day)!=0){
                                                    ss<-which(is.na
(table2[[4]])==T)
                                                     tt<-table2$day[-ss]
                                                     bb<-aa[-tt]
                }
                x<-c(NA,length(bb))
                for(k in 1:length(bb)){
                    ms2<-ms;if(ms<10)ms2=paste("0",ms,sep="")
                    bb2<-bb[k];if(bb[k]<10)bb2=paste("0",bb[k],sep="")

x<-c(table[[1]][1],table[[2]][1],paste(anyo,ms2,bb2,sep=""),NA,NA,anyo,ms,k)
                    table<-rbind(table,x)
                }

            }

then although ndays = daysanyoBIS[ms] and a = FAlse
Script continuous writting new data. ¿Why?

note: this piece is for the leap years, would continue for the remaining
dates

Thanks , again and I´m sorry for the annotation It´s a mix of Spanish,
Italian and English but I think is quite easy for understanding.
-- 
Vale
Para el medioambiente cada gesto cuenta: por favor, no imprimas este e-mail
si no es realmente necesario.
Each one of us can do our bit for the environment: please, do not print this
e-mail unless it is absolutely essential
"Ambientólogo":profesional experto en las Ciencias del Medio Ambiente

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to