全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 LATEX论坛
1154 3
2016-10-19

Turning plain-text output into well-formatted tables can be a repetitive task, especially when many tests or models are being incorporated into a paper.

For R users, there are several methods that can make this task easier (though not much less repetitive), regardless of what typesetting system you use.

LaTeX tables
The xtable package produces LaTeX-formatted tables. Using xtable, specific kinds of R objects, such as linear model summaries, can be turned into "xtables", which can in turn be output to either LaTeX or HTML.

To use:

  • Install the xtable package: install.packages("xtable")
  • Load the xtable package: library(xtable)
  • Create an xtable for the object that you want to export: newobject<-xtable(object)
  • Export your xtabled object to LaTeX: print.xtable(newobject, type="latex", file="filename.tex")

Options

  • To export to HTML instead of LaTeX, use type="html" and use the .html extension in the filename
  • To have R produce the proper markup in the console (instead of writing in to a file) omit the file=filename option

Other word processors
If, instead of LaTeX, you are using Word, OpenOffice, NeoOffice, etc., there is a way to produce more easily formatted tables. Just follow these steps:

  • Create an xtable, as above, and print the output to an HTML file: print.xtable(newobject, type="html", file="filename.html")
  • Open the generated HTML file in your browser (may I recommend Firefox)
  • Copy the table contents and paste them into your word processor
  • Convert the text to a table: In OpenOffice or NeoOffice: Select the text and go to Tools: Text <-> Table and select "Tabs" as the delimiter. In Word: Select the text and go to Table: Convert: Convert Text to Table, and use separate text at tabs

This technique is somewhat more convoluted than creating pure LaTeX output, but it is probably quicker than entering the output by hand.

Note: An alternative to xtable is the R2HTML package, which works similarly, but does not require xtable objects to be created in order to generate HTML output.


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2016-10-19 14:16:29
oliyiyi 发表于 2016-10-19 09:35
Turning plain-text output into well-formatted tables can be a repetitive task, especially when many  ...
谢谢楼主分享的资料
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-11-16 10:40:56
谢谢了,非常有用。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-11-16 11:28:41
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群