[R] Novice problems with write()

Bret Collier bacolli at uark.edu
Wed Feb 4 00:24:50 CET 2004


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")
}

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




More information about the R-help mailing list