Hi there, I would like to write a data output. In first time, a data frame (called "res") is written in a file *csv such as: A B C # names of data 1.5 4.5 7 # values So I use "write.table" which prints "res" to a file "file.csv" write.table(res,file="file.csv",sep="",row.names=TRUE,col.names=TRUE,eol = "\n") After, I would like to append other data to the same file, A B C 1.5 4.5 7 3 6 9 # appended data I use then the same function but with different arguments: write.table(res,file="file.csv",append=TRUE,sep="",row.names=TRUE,col.names=FALSE,eol = "\n") Actually, it doesn't work, the file is overwritten by the new one. I got something like that: A B C 3 6 9 Coul you help me? Thank you in advance Kind regards, Marie-No?lle
> res <- as.data.frame(t(c(A=1,B=2,C=3)))> res A B C 1 1 2 3 > write.table(res, file="file.csv", sep="\t", row.names=F, col.names=T) > write.table(t(4:6), append=T, file="file.csv", sep="\t", row.names=F, col.names=F) > read.csv("file.csv", sep="\t") A B C 1 1 2 3 2 4 5 6 ------------------------------------------------------------------- Jacques VESLOT CNRS UMR 8090 I.B.L (2?me ?tage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr ------------------------------------------------------------------- Marie-No?lle Rolland a ?crit :> Hi there, > > I would like to write a data output. In first time, a data frame (called > "res") is written in a file *csv such as: > > A B C # names of data > 1.5 4.5 7 # values > > So I use "write.table" which prints "res" to a file "file.csv" > write.table(res,file="file.csv",sep="",row.names=TRUE,col.names=TRUE,eol > = "\n") > > After, I would like to append other data to the same file, > > A B C > 1.5 4.5 7 > 3 6 9 # appended data > > I use then the same function but with different arguments: > write.table(res,file="file.csv",append=TRUE,sep="",row.names=TRUE,col.names=FALSE,eol > = "\n") > > Actually, it doesn't work, the file is overwritten by the new one. > > I got something like that: > A B C > 3 6 9 > > Coul you help me? Thank you in advance > > Kind regards, > Marie-No?lle > > ______________________________________________ > 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. >
Difficult to say exactly why it didn't work without knowing exactly what you did. The following works for me:> res<-data.frame(A=1.5,B=4.5,C=7)> write.table(res,file="file.csv",sep=" ",row.names=TRUE,col.names=TRUE,eol = "\n") > res2<-data.frame(3,6,9) > write.table(res2,file="file.csv",append=TRUE,sep=" ",row.names=TRUE,col.names=FALSE,eol="\n") By the way, the extension .csv is usually used for comma delimited format. On 11/09/06, Marie-No?lle Rolland <mrolland at grignon.inra.fr> wrote:> Hi there, > > I would like to write a data output. In first time, a data frame (called > "res") is written in a file *csv such as: > > A B C # names of data > 1.5 4.5 7 # values > > So I use "write.table" which prints "res" to a file "file.csv" > write.table(res,file="file.csv",sep="",row.names=TRUE,col.names=TRUE,eol > = "\n") > > After, I would like to append other data to the same file, > > A B C > 1.5 4.5 7 > 3 6 9 # appended data > > I use then the same function but with different arguments: > write.table(res,file="file.csv",append=TRUE,sep="",row.names=TRUE,col.names=FALSE,eol > = "\n") > > Actually, it doesn't work, the file is overwritten by the new one. > > I got something like that: > A B C > 3 6 9 > > Coul you help me? Thank you in advance > > Kind regards, > Marie-No?lle > > ______________________________________________ > 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. >-- ================================David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP
?write.table >> append = TRUE ? --- Marie-No?lle Rolland <mrolland at grignon.inra.fr> wrote:> Hi there, > > I would like to write a data output. In first time, > a data frame (called > "res") is written in a file *csv such as: > > A B C # names of data > 1.5 4.5 7 # values > > So I use "write.table" which prints "res" to a file > "file.csv" >write.table(res,file="file.csv",sep="",row.names=TRUE,col.names=TRUE,eol> > = "\n") > > After, I would like to append other data to the same > file, > > A B C > 1.5 4.5 7 > 3 6 9 # appended data > > I use then the same function but with different > arguments: >write.table(res,file="file.csv",append=TRUE,sep="",row.names=TRUE,col.names=FALSE,eol> > = "\n") > > Actually, it doesn't work, the file is overwritten > by the new one. > > I got something like that: > A B C > 3 6 9 > > Coul you help me? Thank you in advance > > Kind regards, > Marie-No?lle > > ______________________________________________ > 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. >