Dear list, I would like to export a matrix to a TXT-File by using write.csv (not necessarily). Is there a way to add a header (with additional informations concerning the project) spanning multiple lines to this file before the actual data are listed up? Should look like this: date: filename: number of permutations: ------------ data (as a matrix) Any suggestions? Thnx in advance. cheers Alex
Hi Alex, try this mfile <- "c:\\ex01.txt" nperm <- 12 sDate <- paste("date: ", "2009-12-13", sep="") sFile <- paste("filename: ", mfile, sep="") sPerm <- paste("number of permutations: ", nperm, sep="") mt <- matrix(1:10, 2) sink(mfile) cat(sDate, "\n") cat(sFile, "\n") cat(sPerm, "\n") cat("-----------------------------", "\n\n") print(mt) sink() Best Patrick Walther, Alexander schrieb:> Dear list, > > I would like to export a matrix to a TXT-File by using write.csv (not > necessarily). Is there a way to add a header (with additional > informations concerning the project) spanning multiple lines to this > file before the actual data are listed up? Should look like this: > > > > date: > filename: > number of permutations: > > ------------ > > data (as a matrix) > > > > Any suggestions? Thnx in advance. > > > cheers > > Alex > > ______________________________________________ > R-help at r-project.org 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.
On Mon, Dec 14, 2009 at 4:37 PM, Walther, Alexander < awalthermail@googlemail.com> wrote:> Dear list, > > I would like to export a matrix to a TXT-File by using write.csv (not > necessarily). Is there a way to add a header (with additional > informations concerning the project) spanning multiple lines to this > file before the actual data are listed up? Should look like this: > > > > date: > filename: > number of permutations: > > ------------ > > data (as a matrix) > > > > Any suggestions? Thnx in advance. > > > cheers > > Alex > > >Hi, ?write.table and the argument "append" should be of help. example:> sink("test.csv") > cat("-----------------------------") > cat("\n") > cat("This is \n a test of header") > cat("\n") > cat("-----------------------------") > cat("\n") > sink() >write.table(matrix(rnorm(100),nrow=10),file="test.csv",append=TRUE,sep=",") regards, Gustaf -- Gustaf Rydevik, M.Sci. tel: +46(0)703 051 451 address:Essingetorget 40,112 66 Stockholm, SE skype:gustaf_rydevik [[alternative HTML version deleted]]
On Tue, 15-Dec-2009 at 01:55PM +0100, Gustaf Rydevik wrote: |> Hi, |> |> ?write.table and the argument "append" should be of help. |> example: |> |> > sink("test.csv") |> > cat("-----------------------------") |> > cat("\n") |> > cat("This is \n a test of header") |> > cat("\n") |> > cat("-----------------------------") |> > cat("\n") |> > sink() |> > Or, instead of the use of sink() and cat(), one could use the write() function, also using the append = TRUE argument. |> write.table(matrix(rnorm(100),nrow=10),file="test.csv",append=TRUE,sep=",") |> |> |> regards, |> Gustaf |> |> |> -- |> Gustaf Rydevik, M.Sci. |> tel: +46(0)703 051 451 |> address:Essingetorget 40,112 66 Stockholm, SE |> skype:gustaf_rydevik |> |> [[alternative HTML version deleted]] |> |> ______________________________________________ |> R-help at r-project.org 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. -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___ Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) ..... Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
I have a small request regarding this "append" feature. As it is now if the data is appended to the file so is the header. I would like to have the header only entered once and appends just append the data. Doable? Kevin ---- Patrick Connolly <p_connolly at slingshot.co.nz> wrote:> On Tue, 15-Dec-2009 at 01:55PM +0100, Gustaf Rydevik wrote: > > > |> Hi, > |> > |> ?write.table and the argument "append" should be of help. > |> example: > |> > |> > sink("test.csv") > |> > cat("-----------------------------") > |> > cat("\n") > |> > cat("This is \n a test of header") > |> > cat("\n") > |> > cat("-----------------------------") > |> > cat("\n") > |> > sink() > |> > > > Or, instead of the use of sink() and cat(), one could use the write() > function, also using the append = TRUE argument. > > > |> write.table(matrix(rnorm(100),nrow=10),file="test.csv",append=TRUE,sep=",") > |> > |> > |> regards, > |> Gustaf > |> > |> > |> -- > |> Gustaf Rydevik, M.Sci. > |> tel: +46(0)703 051 451 > |> address:Essingetorget 40,112 66 Stockholm, SE > |> skype:gustaf_rydevik > |> > |> [[alternative HTML version deleted]] > |> > |> ______________________________________________ > |> R-help at r-project.org 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. > > -- > ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. > ___ Patrick Connolly > {~._.~} Great minds discuss ideas > _( Y )_ Average minds discuss events > (:_~*~_:) Small minds discuss people > (_)-(_) ..... Eleanor Roosevelt > > ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. > > ______________________________________________ > R-help at r-project.org 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.
I have a small request regarding this "append" feature. As it is now if the data is appended to the file so is the header. I would like to have the header only entered once and appends just append the data. Doable? Kevin ---- Patrick Connolly <p_connolly at slingshot.co.nz> wrote:> On Tue, 15-Dec-2009 at 01:55PM +0100, Gustaf Rydevik wrote: > > > |> Hi, > |> > |> ?write.table and the argument "append" should be of help. > |> example: > |> > |> > sink("test.csv") > |> > cat("-----------------------------") > |> > cat("\n") > |> > cat("This is \n a test of header") > |> > cat("\n") > |> > cat("-----------------------------") > |> > cat("\n") > |> > sink() > |> > > > Or, instead of the use of sink() and cat(), one could use the write() > function, also using the append = TRUE argument. > > > |> write.table(matrix(rnorm(100),nrow=10),file="test.csv",append=TRUE,sep=",") > |> > |> > |> regards, > |> Gustaf > |> > |> > |> -- > |> Gustaf Rydevik, M.Sci. > |> tel: +46(0)703 051 451 > |> address:Essingetorget 40,112 66 Stockholm, SE > |> skype:gustaf_rydevik > |> > |> [[alternative HTML version deleted]] > |> > |> ______________________________________________ > |> R-help at r-project.org 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. > > -- > ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. > ___ Patrick Connolly > {~._.~} Great minds discuss ideas > _( Y )_ Average minds discuss events > (:_~*~_:) Small minds discuss people > (_)-(_) ..... Eleanor Roosevelt > > ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. > > ______________________________________________ > R-help at r-project.org 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.
Just write the headers once and append as many times as needed? You can append as many datasets as you want. --- On Wed, 12/16/09, rkevinburton at charter.net <rkevinburton at charter.net> wrote:> From: rkevinburton at charter.net <rkevinburton at charter.net> > Subject: Re: [R] write.csv and header > To: "Gustaf Rydevik" <gustaf.rydevik at gmail.com>, "Patrick Connolly" <p_connolly at slingshot.co.nz> > Cc: r-help at r-project.org > Received: Wednesday, December 16, 2009, 3:05 PM > I have a small request regarding this > "append" feature. As it is now if the data is appended to > the file so is the header. I would like to have the header > only entered once and appends just append the data. > > Doable? > > Kevin > > ---- Patrick Connolly <p_connolly at slingshot.co.nz> > wrote: > > On Tue, 15-Dec-2009 at 01:55PM +0100, Gustaf Rydevik > wrote: > > > > > > |> Hi, > > |> > > |> ?write.table and the argument "append" should be > of help. > > |> example: > > |> > > |> > sink("test.csv") > > |> > cat("-----------------------------") > > |> > cat("\n") > > |> > cat("This is \n a test of header") > > |> > cat("\n") > > |> > cat("-----------------------------") > > |> > cat("\n") > > |> > sink() > > |> > > > > > Or, instead of the use of sink() and cat(), one could > use the write() > > function, also using the append = TRUE argument. > > > > > > |> > write.table(matrix(rnorm(100),nrow=10),file="test.csv",append=TRUE,sep=",") > > |> > > |> > > |> regards, > > |> Gustaf > > |> > > |> > > |> -- > > |> Gustaf Rydevik, M.Sci. > > |> tel: +46(0)703 051 451 > > |> address:Essingetorget 40,112 66 Stockholm, SE > > |> skype:gustaf_rydevik > > |> > > |> ??? [[alternative HTML version > deleted]] > > |> > > |> ______________________________________________ > > |> R-help at r-project.org > 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. > > > > -- > > > ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.??? > >? ? ___? ? Patrick > Connolly??? > >? {~._.~}? ? ? ? ? ? > ? ? ???Great minds discuss > ideas? ? > >? _( Y )_? ??? ? ? > ? ???Average minds discuss events > > (:_~*~_:)? ? ? ? ? ? > ? ? ? Small minds discuss people? > >? (_)-(_)? ??? ? ? > ? ? ? ? ? ? ? ? > ? ..... Eleanor Roosevelt > > ??? ? > > > ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. > > > > ______________________________________________ > > R-help at r-project.org > 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. > > ______________________________________________ > R-help at r-project.org > 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. >__________________________________________________________________ Be smarter than spam. See how smart SpamGuard is at giving ju