[R] Writing out in loops

Thomas chesney.alt at gmail.com
Tue Dec 6 10:18:05 CET 2011


I would like to write some data to different files. I can create the  
filename Day1.txt like this:

filen <- paste("Day", l, ".txt", sep="")

and then I'm using a For loop to write out one row of a matrix,  
something like this:

For (j in 1:10)
{
cat(mat[1,j], ",", file=filen, append=TRUE)
}
cat("\n", file=filen, append=TRUE)

but is there a better way to do this?

Thank you,

Thomas



More information about the R-help mailing list