[Bgsa] Help with a 'for loop' in R

Ashkaan Fahimipour ashkaanf at gmail.com
Tue Sep 6 11:49:26 PDT 2011


Hey all, I'm hoping someone will be able to help me. I have a list of 178
food web matrices in R -- I want to export these individually using the
'write.csv' function, but I also want to use the loop number to name each
subsequent .csv file. I have a regional matrix called 'master3' grouped as a
list, I can pull out local food webs using master3[[i]] where i denotes the
i'th food web. I want to export each individual locality as a csv file named
after the corresponding loop number (e.g. for master[[4]], output
'master_4.csv') Something like:

for (i in 1:length(master3)) {
  write.csv(master3[[i]], file = master_i)
}

But that doesn't seem to make R happy. Any help at all would be appreciated,
I'd like to avoid doing it manually.

-Ashkaan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ucr.edu/pipermail/bgsa/attachments/20110906/3f40f30e/attachment.html 


More information about the BGSA mailing list