Novice problems with write()
Bret Collier wrote:
R-Users,
As a relatively new user of R, I have a quick (and probably
simple) question about using write(). I have a population simulation
that I am running and I want to output a set of variables for each run
of the simulation into a text file for use in another program. However,
whenever I attempt to use write(), the only output that I am able to get
is the final numbers from the simulation.
for example:
x <- 5
for (i in 1:10){
z <- x+i
print(z)
write(z, "c:/test.txt")
}
For each i in 1:10 you are printing z to the console and writing z into a file test.txt. Note that you only see the last z in the file, since it has been been overwritten several times, while the output on your console produced by print() has not been not overwritten. Uwe Ligges
In this simple case, with print(z) I can see that z has what I am looking for, but all that is output for the write statement is 15; While this is simplified, it shows my problem. I searched the help files, and on the R website, but I could not find anything addressing this. I suspect that it is my lack of knowledge and I am missing something obvious (or should be using write.table). If anyone could point me in the right direction I would appreciate it. Thanks, Bret Collier Univ. Arkansas
______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html