[R] R: Appending the files

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Apr 21 16:17:16 CEST 2007


On Sat, 21 Apr 2007, Vaibhav Gathibandhe wrote:

> Hi Prof Brian,
>
> Thanks for the solution.
>
> cbind() certainly works in this example, but it won't work in my case.
> I m doing bootstrap and generating lots of data (2 x 10 power 6).
> I tried to create this much big matrix but my machine won't let me do it.
> In cbind() also, the situation will be the same, the difference is that the
> bit matrix will be formed at the end.
>
> That's why i need some way through which i can properly append to the file
> and don't have to create big matrix which i can't.

No one said you needed to create the whole matrix before writing (which 
you seem to be assuming we did say), but you do need to create all of a 
row before writing that row: that is a property of sequential files.

You need to think through the data representation you want on that file: a 
flat ASCII file by rows does not seem a good enough fit.


> On 4/20/07, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
>> 
>> The output is
>> 
>> "","V1","V2","V3"
>> "1",0,0,0
>> "2",0,0,0
>> "","V1","V2","V3"
>> "1",1,1,1
>> "2",1,1,1
>> 
>> and the warning is because no csv-reader is going to make much sense of
>> that.
>> 
>> You want col.names=FALSE on the second call.
>> 
>> 
>> On Fri, 20 Apr 2007, Vaibhav Gathibandhe wrote:
>> 
>> > Hello R-Experts,
>> >
>> > I am a beginner to R. Can someone please look at my problem
>> >
>> > I am trying to append the files in R but couldn't get the answer
>> properly.
>> >
>> > My code is
>> >
>> > mat1<-matrix(0,2,3)
>> > mat2<-matrix(1,2,3)
>> >
>> > write.table(mat1,"foo.csv",sep=",",col.names=NA)
>> > write.table(mat2,"foo.csv", sep=",", col.names=NA, append = TRUE)
>> >
>> > I am getting a warning message:
>> >
>> > Warning message:
>> > appending column names to file in: write.table(mat2, "foo.csv", sep =
>> ",",
>> > col.names = NA, append = TRUE)
>> >
>> > Moreover the data of *mat2* is getting appended to "foo.csv" in the
>> > following way
>> >
>> >       V1    V2     V3 1 0 0 0 2 0 0 0     V1    V2     V3 1 1 1 1 2 1 1
>> 1
>> >
>> > If data is getting appended then why I am getting the warning message?
>> >
>> > Moreover is there any way by which i can get the data of *mat2* beside
>> the
>> > data of *mat1* instead of below?
>> 
>> Not by appending to a file.  You can use cbind() in R.
>> 
>> >
>> >
>> > Thanks and Regards,
>> > Vaibhav Gathibandhe
>> >
>> >       [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > R-help at stat.math.ethz.ch mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> >
>> 
>> --
>> Brian D. Ripley,                  ripley at stats.ox.ac.uk
>> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
>> University of Oxford,             Tel:  +44 1865 272861 (self)
>> 1 South Parks Road,                     +44 1865 272866 (PA)
>> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>> 
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list