Dear R users, I am running a R code which gives me 10 columns and 160 rows. I need to run the code for 100 times and each time I need to store the results in a single file. I do not know how can I store them in a single file without over writting the results? Thanks Alex [[alternative HTML version deleted]]
You could put all of your results into a single list, then just save the list. Or, functions like write.table and write have an append argument, set that to true and the information will be appended to the file rather than overwriting it. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Alex Roy > Sent: Wednesday, January 13, 2010 8:00 AM > To: r-help at r-project.org > Subject: [R] How can I store the results > > Dear R users, > I am running a R code which gives me 10 columns > and > 160 rows. I need to run the code for 100 times and each time I need to > store > the results in a single file. > I do not know how can I store them in a single file without over > writting > the results? > > Thanks > > Alex > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.
Collect the results in a list (one entry for each matrix) and then 'save' the list. When you 'load' it back in, you can easily reference each element for further processing. On Wed, Jan 13, 2010 at 9:59 AM, Alex Roy <alexroy2008@gmail.com> wrote:> Dear R users, > I am running a R code which gives me 10 columns and > 160 rows. I need to run the code for 100 times and each time I need to > store > the results in a single file. > I do not know how can I store them in a single file without over writting > the results? > > Thanks > > Alex > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]]
On Wed, 2010-01-13 at 15:59 +0100, Alex Roy wrote:> Dear R users, > I am running a R code which gives me 10 columns and > 160 rows. I need to run the code for 100 times and each time I need to store > the results in a single file. > I do not know how can I store them in a single file without over writting > the results?In a list? results <- vector(mode = "list, length = 100) for(i in seq_along(results) { ## do something ## .... ## store result for iteration i results[[i]] <- something } results will now contain 100 matrices of dim 160x10. HTH G> > Thanks > > Alex > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
If you absolutely need a single file for each iteration, you can also include the iteration number into your output filename. for(i in 1:dim(your input data)[1]) { results<- your calculation write.csv(results, paste("filename", "_", i, sep="")) } Arnaud Date: Wed, 13 Jan 2010 15:59:37 +0100 From: Alex Roy <alexroy2008@gmail.com> To: r-help@r-project.org Subject: [R] How can I store the results Message-ID: <8bdeb1b51001130659n6341b0e6oe42a029efb7a135c@mail.gmail.com> Content-Type: text/plain Dear R users, I am running a R code which gives me 10 columns and 160 rows. I need to run the code for 100 times and each time I need to store the results in a single file. I do not know how can I store them in a single file without over writting the results? Thanks Alex [[alternative HTML version deleted]]