[R] how do I name data frames and files according to the index of a for loop?

Ken Ervin ervinjudo at gmail.com
Thu Oct 8 05:10:31 CEST 2009

Thanks in advance for reading my question.
This is my first time working with R, though I have some intro-level 
experience with other languages.
I am writing a program that performs a certain set of calculations on 
each row of a list of data, and here's what I have so far:

for (i in 1:2858) {
        Calc_1 <- some_stuff  
        Calc_2 <- some_more_stuff
        Calc_3 <- some_other_stuff

        Data_frame_name <- data.frame(Calc_1, Calc_2, Calc_3)
        write.table(Data_frame_name,file="~/file/goes/here.csv", append 
= FALSE, sep = "\t",row.names = FALSE, col.names = c("Calc_1", "Calc_2", 
"Calc_3"),qmethod = "double")

The naming of the data frame and the writing of the file go swimmingly, 
if I do it ONCE, outside of the for loop.  I want to embed the process 
in the for loop written above, run it 2858 times, and get that many data 
frames and .csv files that I can then manipulate.  In order to do so, I 
would like to name the data frames and/or files by their respective 
index, to get:

I would also like to produce the .csv files:

I've been noodling over this for a while and have looked all over but I 
can't seem to get the syntax right.  Any help at all would be appreciated.
Thanks again!
-Ken Ervin

More information about the R-help mailing list