Re: [R] Save output

From: Mike Lawrence <Mike.Lawrence_at_Dal.Ca>
Date: Mon 03 Oct 2005 - 22:00:57 EST

I think this is what you're looking for:

file_name_root = "myfile"

for(i in 1:10)

        result<- of_some_function

        out_file<-paste(file_name_root, i, ".txt", sep = "")

        write.table(result, file = out_file)

}

the above code produces 10 files ("myfile1.txt" to "myfile10.txt"), each containing whatever was calculated on that loop. If you have loops within loops
and you want to write during the innermost loop, remember to take this into account like so:

file_name_root = "myfile"

for (i in 1:10)

        for(q in 1:10)

                result<- of_some_function

                out_file<-paste(file_name_root, i, q, ".txt", sep = "")

                write.table(result, file = out_file)

        }

}

That way, when "i" iterates and when "q" resets to 1, you don't write over your
previous output.

Quoting Frank Schmid <frank.schmid@vwi.unibe.ch>:

> Dear R-Mastermind
>
>
> Within a while or a for-loop, is there a way that I can save to disk the
> results of the previous calculations at the end of each loop with filenames
> called "file01.Rdata", "file02.Rdata" etc?
>
> So far, I have tried to write the outcome of each loop in a 3 dimensional
> array and saved it just once after the loop. Or is there another way so that
> I can keep the resulting matrix of every step in the loop?
>
> Thank you very much for your help
>
>
> Frank Schmid
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

-- 

Mike Lawrence, BA(Hons)
Research Assistant to Dr. Gail Eskes
Dalhousie University & QEII Health Sciences Centre (Psychiatry)

Mike.Lawrence@Dal.Ca

"The road to Wisdom? Well, it's plain and simple to express:
Err and err and err again, but less and less and less."
- Piet Hein

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Mon Oct 03 22:04:54 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:09:41 EST