[R] How to loop several binary files from two directories?

Jonsson amen.alyaari at Bordeaux.inra.fr
Mon Mar 4 12:08:51 CET 2013


I have two binary files(rasters) with the same dimensions. The first file is
called `over`  and the second is `corr`. I want to replace values in `over`
by `NA` whenever `corr` is greater than 0.5.


to read the two files we can use:

        conne <- file("C:corr.bin","rb")
        over <- readBin(conne, numeric(), size=4,  n=1440*720, signed=TRUE)
        frf <- file("C:cor206.bin","rb")
        corr <- readBin(frf, numeric(), size=4,  n=1440*720, signed=TRUE)
        
to replace values in `over` by `NA` whenever `corr` is greater than 0.5:
                               
                         over[corr > 0.4] = NA
to write the results:

      to.write = file(paste("C:flag.bin", sep=""), "wb")
      writeBin(as.double(over), to.write, size = 4)
      close(to.write)
              
            
Now I want to do the same but with 24 files(12 files in each directory) i.e.
to loop thru several files :
so file1 from the first directory with file1 from the second directory and
so on....

To read the files from both directories

    firstdirctory   <- list.files("C:final-2010", "*.bin", full.names =
TRUE)
    seconddirctory   <- list.files("C:jop-2012", "*.bin", full.names = TRUE)



--
View this message in context: http://r.789695.n4.nabble.com/How-to-loop-several-binary-files-from-two-directories-tp4660205.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list