Formatting a Table in Word | R to Tab-Delimited to APA Style
[This article was first published on Jeromy Anglim's Blog: Psychology and Statistics, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
The following post sets out my procedure for importing a tab-delimited table of data produced in R into Microsoft Word and formatting it.Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Prior to importing table:
- Run macro which does the following
- Insert Caption: References – Insert Caption (Label = Table)
- Insert line for Table Title and assign style Table Title (i.e., an italicised style)
- Insert line for table to be placed and assign style (Table Text).
- Copy the tab-delimited text file and Paste into desired locations of Word document
- Convert to table: Insert – Table – Convert Text To Table (Separate = Tabs)
- Format table
- Assign Style to content of table (mine is called Table Text)
- Italicise: e.g., “Note”, some statistics
- Superscript: specific notes, exponents (e.g., R^2)
- Characters not allowed in R (e.g., dash)
- Adjust column widths
- Adjust cell alignment
- decimal tab (select numeric columns; paragraph dialog box; tabs; tab stop position = 1cm; alignment = decimal)
- centred
- left-aligned for row names
- Mark lines
- Remove all lines
- Add lines, typically 3 rows (above 1st; below 1st; below last)
- Check table accuracy
- Interpret and add describing text; to ensure text stays up to date as tables are added and deleted, insert a cross reference to the Table Caption (Reference – Cross-Reference: Reference Type = Table; Insert Reference to = Only label and number)
- Change status in output meta-file: I have an Excel spreadsheet which lists all tables that need to be created. Once a table is created it is recorded as done in the spreadsheet.
Future refinements: I am looking into ways of automating more of the above possibly by using a little meta data (to store column width information, alignment, and so on), a little mark up language (to handle superscripts, italics, special characters), and a vb macro to apply the meta data and markup language in Word.
To leave a comment for the author, please follow the link and comment on their blog: Jeromy Anglim's Blog: Psychology and Statistics.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.