I have two directories 
https://echange-fichiers.inra.fr/get?k=AcHKdNI4No44GEsj7PK with 12 (global
maps)binary files in each.I used the code given below to calculate the
spatial correlation between these files and it worked well(the output is a
global correlation map). I wonder if there is a simple way to calculate RMSE
and bias along with cor.so finally we get three outputs (bias map,RMSE
map,cor map) instead of only(cor map).

Could anyone tell me how to add the RMSE function written below  the code of
Corr so that When I run the code.I get both RMSE map,corr map.
 
RMSE function
RMSE <- function(obs, sat){
  sqrt(mean((obs-sat)^2, na.rm=T))
                                               }

Corr code

         dir1 <- list.files("D:\\2010\\data\\monthly", "*.bin", full.names =
TRUE)
         dir1<- mixedsort(dir1)
         dir2 <- list.files("D:\\RE01\\MIR_CLF3MD\\2010\\final-2010",
"*.envi", full.names = TRUE)
         dir2<- mixedsort(dir2)
         file_tot<-array(dim=c(1440,720,12,2))
        for(i in 1:length(dir1)){
        file_tot[,,i,1] <- readBin(dir1[i], numeric(), size = 4 ,n = 1440 *
720 , signed = T)
       file_tot[,,i,2] <- readBin(dir2[i], numeric(), size = 4 ,n = 1440 *
720 , signed = T)
       }
       resultsr<-apply(file_tot,c(1,2),function(x){cor(x[,1],x[,2])})
           to.write = file(paste("C:\\corrCCIandSMOS2010.bin",sep=""),"wb")
                 writeBin(as.double(resultsr), to.write, size = 4)
I am gratefull for any ideas



--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-add-a-function-to-another-written-code-tp4656499.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.

Reply via email to