[R] read multiaple files within one folder

jim holtman jholtman at gmail.com
Fri Apr 6 16:19:03 CEST 2012


Why "didn't seem to be right"?  Are there error messages?  I assume
you have at least 6GB of real memory since you single copy of
Testarray requires 3GB.  Is your already in a 'binary' file?  If so,
why are you defining your matrix as numeric?  Should you be using
'array(0L, dim = c(1460, 720, 360))'?  This might be the cause of your
problem.

Alway start with a small subset.  Read a single file into an array and
see if the values are correct.  No telling what you are getting since
you are reading binary values in.

On Fri, Apr 6, 2012 at 9:25 AM, Amen <amen.alyaari at bordeaux.inra.fr> wrote:
> 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.
>
> ______________________________________________
> R-help at 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.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.



More information about the R-help mailing list