HI, Check these links: http://r.789695.n4.nabble.com/Re-new-question-td4659908.html http://r.789695.n4.nabble.com/Re-reading-data-td4658705.html#a4659751
It shows reading files (not binary files) from multiple subdirectories and doing some calculations. You may need to change it according to your needs ('read.table' to 'readBin' etc.) A.K. ----- Original Message ----- From: Jonsson <amen.alya...@bordeaux.inra.fr> To: r-help@r-project.org Cc: Sent: Monday, March 4, 2013 6:08 AM Subject: [R] How to loop several binary files from two directories? 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. ______________________________________________ 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.