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

Ashkaan Fahimipour ashkaanf at gmail.com
Tue Sep 6 12:09:07 PDT 2011


Thanks to Mauricio and Elizabeth. If anyone's curious the solution is below:
---

name.temp<-paste('name', as.character(i), '.csv', sep='')

#This will create the table, tab-separated

write.table(YOURTABLEHERE,file=name.temp,sep="\t", row.names=FALSE, quote=
FALSE)
---

Thanks again,

-A

On Tue, Sep 6, 2011 at 11:49 AM, Ashkaan Fahimipour <ashkaanf at gmail.com>wrote:

> 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/52af582b/attachment.html 


More information about the BGSA mailing list