Message-ID: <CAM_vju=-_XT1MLdRJMevz-ognV8_ePbODTzBL+xxod8BzR0kUg@mail.gmail.com>
Date: 2011-12-06T15:07:23Z
From: Sarah Goslee
Subject: Writing out in loops
In-Reply-To: <25F43847-81F3-4231-8D4F-DE54B85E6084@gmail.com>
Is there some reason you can't create the entire file in R and then write it
out in a single step?
It looks like you're writing out
mat[1, 1:10]
so you could just use
write.table(mat[1, 1:10], filen)
Can you expand on what you're trying to do?
Sarah
On Tue, Dec 6, 2011 at 4:18 AM, Thomas <chesney.alt at gmail.com> wrote:
> 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
>
--
Sarah Goslee
http://www.functionaldiversity.org