[R-sig-Geo] apply help

Amen Alyaari amen.alyaari at bordeaux.inra.fr
Fri Jul 12 18:07:34 CEST 2013


Hello All,

There are 600 (global map)files (1440 sample * 720 lines)in three 
directories dir1 and dir2,and dir3 (600 files in each directory) which 
have the same format ,byte,extend,etc.
  I computed the `err` between three datasets using the function and 
code given below as follows:


  function:

        err<-function(pred,obs,mod,na.rm=TRUE){
             sqrt(mean(((pred-obs)*(pred-mod)), na.rm = na.rm))}

read the files:

         dir1 <- list.files("/donnees/notghi", "*.img", full.names = TRUE)
         dir2 <- list.files("/donnees/baieSt", "*.img", full.names = TRUE)
         dir3 <- list.files("/donnees/modt", "*.img", full.names = TRUE)
  code:

         file_tot<-array(dim=c(1440,720,600,3))## worked well
    for(i in 1:length(dir3)){
   file_tot[,,i,1] <- readBin(dir1[i], double(), size = 4 ,n = 1440* 720 
, signed = T)
   file_tot[,,i,2] <- readBin(dir2[i], double(), size = 4 ,n = 1440 * 
720, signed = T)
    file_tot[,,i,3] <- readBin(dir3[i], double(), size = 4 ,n = 1440 * 
720, signed = T)
     }

Now compute based on the function:

  result<-apply(file_tot,c(1,3),function(x){err(x[,1],x[,2],x[,3])})

               Is this line right?

This worked without errors but I checked the results and they were crap:
-the size of the was 3859kb instead of 4050kb.
-it should by a global map with some values over lane but I got map of 
just horizontal lines

  may be: indices or confusing choice of margin with value of index

Any help

Cheers,

-- 
Amen Alyaari, UPMC
PhD student
Unit of Functional Ecology&  Environmental Physics [EPHYSE]
National Institute of Agricultural Research [INRA].
71, Avenue Edouard Bourlaux
33140 Villenave d'Ornon
Téléphone : +33(0) 5 57 12 24 27
Fax : +33 (0)5 57 12 24 20
FRANCE



More information about the R-sig-Geo mailing list