[R] R: Appending the files

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Apr 21 04:55:53 CEST 2007


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



More information about the R-help mailing list