-3

Suppose we have files in one folder file1.bin, file2.bin, ... , and file1460.bin in directory C:\R\Data 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 average and so on till 1460.in the end will get 360 files I tried to have them in a list,but did not know how to make the loop.

How do I read multiple files and manupulat them? in R language
I have been wasting countless hourse to figuer it out.any help

Sam DeHaan
  • 9,916
  • 2
  • 37
  • 44
hkfidd
  • 3
  • 3
  • Here is a link that might be helpful, although the link does not seem to address *.bin files specifically. http://www.ats.ucla.edu/stat/r/code/read_multiple.htm – Mark Miller Apr 05 '12 at 16:18
  • Perhaps a helpful starting point: http://stackoverflow.com/questions/6420207/manipulating-multiple-files-in-r – Ben Bolker Apr 05 '12 at 18:07
  • See also your other question http://stackoverflow.com/questions/10128084/how-do-i-read-multiple-binary-files-in-in-different-folders-in-r – Paul Hiemstra Apr 12 '12 at 17:54

1 Answers1

0
results <- array(dim=360)
for (i in 1:360){
  results <- mean(yourlist[[(i*4):(i*4+3)]])
}

YMMV with the mean(yourList) call, but that structure would be how you could loop through the data once it's loaded.

Jeff Allen
  • 16,637
  • 8
  • 47
  • 70
  • Thanks alot.in fact here is my code listfile – hkfidd Apr 06 '12 at 12:09
  • Sorry ignore the previous .Thanks alot.in fact here is my code listfile – hkfidd Apr 06 '12 at 12:21
  • As @Mark suggested, you may be better off looking at a resource like: http://www.ats.ucla.edu/stat/r/code/read_multiple.htm. It's not really clear what your specific problem is. If you can post a couple of the files online, maybe I could revise the answer. The basic idea is that you'll load all of the files into a list, then loop through and take the mean of every 4 using something like the loop above. – Jeff Allen Apr 06 '12 at 14:27
  • Thanks Jeff.where can I upload the files so you can have alook on them or if you give me your email,i send them to. – hkfidd Apr 06 '12 at 14:37
  • is this right??? Testarray – hkfidd Apr 06 '12 at 14:39
  • Without access to your data, I really have no idea if that's right. Typically, people post it publicly online and share the URL in the question. – Jeff Allen Apr 07 '12 at 15:25
  • https://www.dropbox.com/home here is one file out of 365 files in one folder that I want to work on – hkfidd Apr 09 '12 at 14:41