Hello,

I believe the error is in function 'g'. If I'm right, follow these steps

1. Just before the first if include
flag <- TRUE
2. Just before for(y in ord) include
flag <- FALSE
3. Just before break include
flag <- TRUE
3. Change the return value form simply x to
if(flag) x else NA


The code loops through the ordered matrix until it finds no NAs in the respective df.list element. Nothing guarantees that there are such list elements. The changes above check it by setting a flag.

Rui Barradas

Em 05-06-2012 10:54, jeff6868 escreveu:
Thanks again but my errors are still here. Is it maybe coming from the next
fonction (I combinate these 2 functions but I thought it was coming from the
first one):

process.all<- function(df.list, mat){

         f<- function(station)
              na.fill(df.list[[ station ]], df.list[[ max.cor[station] ]])

         g<- function(station){
         x<- df.list[[station]]
         if(any(is.na(x[1:8700,1]))){
             mat[row(mat) == col(mat)]<- -Inf
             nas<- which(is.na(x[1:8700,1]))
             ord<- order(mat[station, ], decreasing = TRUE)[-c(1,
ncol(mat))]
             for(y in ord){
                 if(all(!is.na(df.list[[y]][1:8700,1][nas]))){
                     xx<- df.list[[y]][1:8700,1]
                     new<- data.frame(xx=xx)
                     x[1:8700,1][nas]<- predict(lm(x[1:8700,1]~xx,
na.action=na.exclude), new)[nas]
                     break
                 }
             }
         }
         x
     }

         n<- length(df.list)
         nms<- names(df.list)
         max.cor<- sapply(seq.int(n), get.max.cor, corhiver2008capt1)
         df.list<- lapply(seq.int(n), f)
         df.list<- lapply(seq.int(n), g)
         names(df.list)<- nms
         df.list
     }

     refill<- process.all(lst, corhiver2008capt1)
     refill<- as.data.frame(refill)

The error is when "refill" is created. It applies "process.all" in which
"na.fill" is also used. Do you see perhaps any error or missing code which
could create this NA problem when I introduce "only NAs" files?

--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-ignore-NA-with-NA-or-NULL-tp4632287p4632388.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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.

______________________________________________
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