Re: [R] questions about R

From: Marc Schwartz <MSchwartz_at_mn.rr.com>
Date: Sun 02 Oct 2005 - 02:21:54 EST

On Sat, 2005-10-01 at 08:59 -0700, James Anderson wrote:
> Hi,
> I am new to R. I have one question about outputing
> files in a loop; Suppose I have the following loop:
>
> for (i in 1:10) {
> temp = 100*2 matrix;
> }
> I want to output the value of temp into 10 files with
> each file containing the number of looping index (i.e,
> file1.csv, file2.csv, ...) without headers. How can I
> realize this?
> Thanks.
>
> James

See ?write.table for the file creation and ?paste for creating the filenames themselves:

for (i in 1:10) {
  temp = matrix(rnorm(200), ncol = 2)
  write.table(temp, file = paste("file", i, ".csv", sep = ""),

              row.names = FALSE, col.names = FALSE, sep = ",") }

HTH, Marc Schwartz



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 Sun Oct 02 02:33:49 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:08:02 EST