Zach Feinstein
2013-Nov-18 14:42 UTC
[R] Providing a Title for a Write.Table - Thinking of Titles in SPSS CTABLES
I understand how I may use message() to provide some output on which run I will be looking at. However, I wish to automate it, and have it written out to a tab-delimited file. Below is the command to output my coefficients: write.table(zbetas, file = "z_coeffs.csv", sep="\t", append = TRUE) I do this run multiple times. It appends the latter results to the end of my .csv file. Is there a way to say just before the write.table something to the effect of: title("First Run", append = TRUE)? Or perhaps there is a sub-command in the write.table to accomplish this. So when I interactively run my code it could be something like: First run Coeff1 0.34 Coeff2 0.96 Second run Coeff1 0.47 Coeff2 0.95 Thank you very much in advance. Zach Feinstein zfeinstein@isgmn.com<mailto:zfeinstein@isgmn.com> (952) 277-0162 (612) 590-4813 (mobile) [[alternative HTML version deleted]]
Adams, Jean
2013-Nov-19 13:35 UTC
[R] Providing a Title for a Write.Table - Thinking of Titles in SPSS CTABLES
One way to do it, is just to insert another write.table() command giving the text you want to write. Here's a simple example: myfile <- "c:/temp/junk.csv" for(i in 1:5) { df <- data.frame(x=rnorm(3), y=rnorm(3)) write.table(paste0("Run #", i), myfile, sep="\t", append=(i!=1), col.names=FALSE, row.names=FALSE) write.table(df, myfile, sep="\t", append=TRUE, col.names=FALSE) } Jean On Mon, Nov 18, 2013 at 8:42 AM, Zach Feinstein <zfeinstein@isgmn.com>wrote:> I understand how I may use message() to provide some output on which run I > will be looking at. However, I wish to automate it, and have it written out > to a tab-delimited file. Below is the command to output my coefficients: > > write.table(zbetas, file = "z_coeffs.csv", sep="\t", append = TRUE) > > I do this run multiple times. It appends the latter results to the end of > my .csv file. > > Is there a way to say just before the write.table something to the effect > of: > > title("First Run", append = TRUE)? > > Or perhaps there is a sub-command in the write.table to accomplish this. > > So when I interactively run my code it could be something like: > > First run > Coeff1 0.34 > Coeff2 0.96 > > Second run > Coeff1 0.47 > Coeff2 0.95 > > Thank you very much in advance. > > Zach Feinstein > zfeinstein@isgmn.com<mailto:zfeinstein@isgmn.com> > (952) 277-0162 > (612) 590-4813 (mobile) > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]