0

I usually use the following code for writing the results in a file in c:\...

y=rnorm(1000)
x=rep(0,length(y))
df=data.frame(rep(0,length(y)) , rep(0,length(y)))
for(i in 1:1000){
x[i]=y[i]+1
df[i,]=c(i,x[i])

print(df[i,])
flush.console()
}
write.table(df,"C:/.../results.txt")

I sometime (in more complicated situations) have ERROR in for loop, so in write.table we will have nothing. My question is: How to write over df line by line in "c:\..." in this for loop

Math
  • 1,274
  • 3
  • 14
  • 32
  • Have you seen writeLines? [Write lines of text to a file in R](https://stackoverflow.com/questions/2470248/write-lines-of-text-to-a-file-in-r) – Ale Aug 30 '17 at 14:48
  • I'm not sure what you're trying to achieve, maybe you can clarify? Maybe using `write.table(df[i,],"C:/.../results.txt", append = True)` inside of your loop is what you're looking for? – don joe Aug 30 '17 at 15:43

0 Answers0