[R] read multiaple files within one folder

Amen amen.alyaari at Bordeaux.inra.fr
Fri Apr 6 15:25:31 CEST 2012


Suppose we have files in one folder file1.bin, file2.bin, ... , and
1460slice(file) with dim of 720 * 360 in directory C:\\PHD\\Climate
Data\\Wind\\   and we want to read them and make a loop to go from 1 to 4
and take the average,  then from 4 to 8 and so on till 1460. in the end we
will get 365 files . I need those 365 files to be in one  new folder for
later use in my model
I tried using this code but didnt seem to be right :
Testarray<-array(0, dim=c(1460,720,360))
listfile<-dir("C:\\PHD\\Climate Data\\Wind\\")
for (i in c(1:1460)) {
     Testarray <- file(listfile[i], "rb")
      Testarray[i,,]<- readBin(conne, integer(), size=2,  n=360*720,
signed=F)
             results <- mean(listfile[[(i*4):(i*4+3)]])
              results1<-    writeBin(results)
close(conne)
}
Thanks in advance




--
View this message in context: http://r.789695.n4.nabble.com/read-multiaple-files-within-one-folder-tp4537394p4537394.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list