[R] write.csv and header

Patrick Hausmann patrick.hausmann at uni-bremen.de
Mon Dec 14 17:24:20 CET 2009


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.




More information about the R-help mailing list