|
Does anyone know of a way to specify the alignment of individual columns in a data frame so that after using write.table the columns are aligned in the file?
|
|
I do not know of any option in write.table() that would allow a
variable spacer, such as padding with spaces to make columns centered or right aligned. Everything is just separated somehow. You could look at ?format or ?sprintf which have padding/alignment options. Once you had properly padded character data, you could just use writeLines() to push it to a file. Cheers, Josh On Fri, Aug 10, 2012 at 6:39 PM, sharx <[hidden email]> wrote: > Does anyone know of a way to specify the alignment of individual columns in a > data frame so that after using write.table the columns are aligned in the > file? > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Align-columns-in-data-frame-write-table-tp4640007.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [hidden email] 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. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/ ______________________________________________ [hidden email] 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. |
|
In reply to this post by sharx
On Aug 10, 2012, at 6:39 PM, sharx wrote: > Does anyone know of a way to specify the alignment of individual > columns in a > data frame so that after using write.table the columns are aligned > in the > file? Do you mean by padding with spaces? set numzer.pad to the desired width and then perhaps using lapply(dfrm, function(x) sprintf(paste('%0', numzer.pad, 'i', sep=''), x) You might need to check for the class of the columns because the letter in the format string for sprintf is different fo numbers and characters. -- David Winsemius, MD Alameda, CA, USA ______________________________________________ [hidden email] 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. |
|
In reply to this post by sharx
HI,
Not sure how you want to align the columns. If you want to write the columns in fixed width format, you can use, write.fwf() from library(gdata). A.K. ----- Original Message ----- From: sharx <[hidden email]> To: [hidden email] Cc: Sent: Friday, August 10, 2012 9:39 PM Subject: [R] Align columns in data frame write.table Does anyone know of a way to specify the alignment of individual columns in a data frame so that after using write.table the columns are aligned in the file? -- View this message in context: http://r.789695.n4.nabble.com/Align-columns-in-data-frame-write-table-tp4640007.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ [hidden email] 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. ______________________________________________ [hidden email] 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. |
| Powered by Nabble | Edit this page |
