[R] Save output

2005-10-03 Thread Frank Schmid
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


Re: [R] Save output

2005-10-03 Thread vincent
Frank Schmid a écrit :

 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?

as a toy example :

for (i in 1:nbfiles)
  {
  fullname = paste(myfile_,i, sep=);
  write.table(intable, fullname);
  }

see
?paste
hih

__
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


Re: [R] Save output

2005-10-03 Thread Mike Lawrence
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 [EMAIL PROTECTED]:

 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)

[EMAIL PROTECTED]

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


Re: [R] Save output

2005-10-03 Thread Romain Francois
Le 03.10.2005 12:30, Frank Schmid a écrit :

 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
  

?save
?sprintf

for(i in 1:12){
 tmp - rnorm(10) # change it with your computations
 save(tmp, file=sprintf('file%02d.RData',i))
}

Romain

-- 
visit the R Graph Gallery : http://addictedtor.free.fr/graphiques
 ~ 
~~  Romain FRANCOIS - http://addictedtor.free.fr ~~
Etudiant  ISUP - CS3 - Industrie et Services   
~~http://www.isup.cicrp.jussieu.fr/  ~~
   Stagiaire INRIA Futurs - Equipe SELECT  
~~   http://www.inria.fr/recherche/equipes/select.fr.html~~
 ~ 

__
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