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? Thanks and Regards, Vaibhav Gathibandhe [[alternative HTML version deleted]]
--- Vaibhav Gathibandhe <gathibandhe.vaibhav at gmail.com> 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?I'm a newbie too, but I think it is just a "warning". :) I suspect it is just to tell you that you are appending to a file and not creating a new file. Iwas a bit upset the first time I saw it until I realised the write command was working just fine.> > Moreover is there any way by which i can get the > data of *mat2* beside the > data of *mat1* instead of below?I suspect that you would have to join the two matrices together in R. cbind the two matrices xx <- cbind(mat1, mat2) and then save the resulting larger matrix X . Will that work?
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