Reputation: 55
I need some help please, i have this file and i'm getting some results i shouldn't but donÄt know where to find for the error, i've been going through every single line of code for the past days and i cannot seem to find it.
So, i have a loop and i should have my results in a txt file.
Now the correct file should be something like:
413062.079096717
413062.079096717
413062.079096717
413062.079096717
413062.079096717
But i get something like:
"x"
"1" 459585.393096583
I know this is not much, but based in the output, can you understand anything?
Thanks
Upvotes: 0
Views: 29
Reputation: 21443
One way to solve it is to use the cat
function:
e.g.
for (i in 1:5) {
X = 413062.079096717
cat(X, "\n", file='myfile.txt', append=TRUE)
}
Notes:
"\n"
will print a newline after your variable, file
allows a filename (you can also print to screen at first by omitting this one), andappend=TRUE
will make sure you don't keep overwriting the file every time you writeUpvotes: 0
Reputation: 2414
If you have a write....
command in your code, then make sure you've got the arguments row.names=FALSE
and col.names=FALSE
. You say it's in a loop - if you also don't have append=TRUE
as an argument, the file will be getting over-written for each loop. Unfortunately, if the file exists already when you enter the loop, it won't get cleared, so either unlink
it prior to entering the loop, or have something along the lines of append=(i!=1)
if i being one identifies the first iteration of the loop
Upvotes: 1