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
questions about R
2 messages · James Anderson, Marc Schwartz
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