基本R - 输出基本R相关表->乳胶或文本

发布于 2024-10-18 14:02:18 字数 565 浏览 6 评论 0原文

我正在使用 http://myowelt 生成关联表。 blogspot.com/2008/04/beautiful-correlation-tables-in-r.html

然而,我没有成功地将文件输出到可用的 LaTex 文件或文本文件。 我使用 sink() 将数据保存到文本文件失败。

假设我使用以下命令:

corstarsl(lpp_axis1)

如何将输出传输到文本文件?我已阅读有关接收器的文档,但我在某处遗漏了一个步骤。 (我打开连接,执行命令,取消链接文件,然后什么也没找到。)

我还尝试在 tex 文件中使用 xtable(cortstarsl(lpp_axis1)) 的输出,但我收到了“未找到元素表”错误。我对 Tex 的了解不够,无法跟踪问题的根源。

输出此数据的建议? 关于创建关联表的其他建议?

I am generating a correlation table with http://myowelt.blogspot.com/2008/04/beautiful-correlation-tables-in-r.html

I am not successful, however, in outputting the file to a usable LaTex file or text file.
I have been unsuccessful using sink() to save the data to a text file.

Suppose I am using the following command:

corstarsl(lpp_axis1)

How would I pipe the output to a text file? I've read the documentation on sink and I'm missing a step somewhere. (I open the connection, execute the command, unlink the file and then I find nothing.)

I've also tried using the output from xtable(cortstarsl(lpp_axis1)) in a tex file yet I receive a "element table not found error. I do not know enough about Tex to track the source of the problem.

Suggestions for outputting this data?
Other suggestions for creating a correlation table?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘香 2024-10-25 14:02:18

使用您链接到的网页中的代码,我得到(使用内置的 airquality 数据):

> require(Hmisc)
> require(xtable)
> xtable(corstarsl(airquality))
% latex table generated in R 2.12.1 by xtable 1.5-6 package
% Mon Feb 21 20:00:34 2011
\begin{table}[ht]
\begin{center}
\begin{tabular}{rlllll}
  \hline
 & ozone & solar.r & wind & temp & month \\ 
  \hline
ozone &  &  &  &  &  \\ 
  solar.r &  0.35*** &  &  &  &  \\ 
  wind & -0.60*** & -0.06  &  &  &  \\ 
  temp &  0.70*** &  0.28*** & -0.46*** &  &  \\ 
  month &  0.16  & -0.08  & -0.18*  &  0.42*** &  \\ 
  day & -0.01  & -0.15  &  0.03  & -0.13  & -0.01  \\ 
   \hline
\end{tabular}
\end{center}
\end{table}

因此,接下来的问题是如何将此 TeX 输出获取到文件。这里的capture.output()是一个朋友:

> capture.output(xtable(corstarsl(airquality)), file = "mytable.tex")

它将代码输出到名为mytable.tex的文件:

$ cat mytable.tex 
% latex table generated in R 2.12.1 by xtable 1.5-6 package
% Mon Feb 21 20:01:03 2011
\begin{table}[ht]
\begin{center}
\begin{tabular}{rlllll}
  \hline
 & ozone & solar.r & wind & temp & month \\ 
  \hline
ozone &  &  &  &  &  \\ 
  solar.r &  0.35*** &  &  &  &  \\ 
  wind & -0.60*** & -0.06  &  &  &  \\ 
  temp &  0.70*** &  0.28*** & -0.46*** &  &  \\ 
  month &  0.16  & -0.08  & -0.18*  &  0.42*** &  \\ 
  day & -0.01  & -0.15  &  0.03  & -0.13  & -0.01  \\ 
   \hline
\end{tabular}
\    end{center}
\end{table}

对于“纯”分隔文本输出,也许转储到文字处理器中或电子表格,请尝试 write.table(),例如:

> write.table(corstarsl(airquality), file = "mytable2.txt")

生成的文件如下所示:

$ cat mytable2.txt 
"ozone" "solar.r" "wind" "temp" "month"
"ozone" "" "" "" "" ""
"solar.r" " 0.35***" "" "" "" ""
"wind" "-0.60***" "-0.06 " "" "" ""
"temp" " 0.70***" " 0.28***" "-0.46***" "" ""
"month" " 0.16 " "-0.08 " "-0.18* " " 0.42***" ""
"day" "-0.01 " "-0.15 " " 0.03 " "-0.13 " "-0.01 "

您可以根据自己的喜好更改引用和分隔符 - 请参阅 ?write.table

Using the code from the web page you link to, I get (with the built in airquality data):

> require(Hmisc)
> require(xtable)
> xtable(corstarsl(airquality))
% latex table generated in R 2.12.1 by xtable 1.5-6 package
% Mon Feb 21 20:00:34 2011
\begin{table}[ht]
\begin{center}
\begin{tabular}{rlllll}
  \hline
 & ozone & solar.r & wind & temp & month \\ 
  \hline
ozone &  &  &  &  &  \\ 
  solar.r &  0.35*** &  &  &  &  \\ 
  wind & -0.60*** & -0.06  &  &  &  \\ 
  temp &  0.70*** &  0.28*** & -0.46*** &  &  \\ 
  month &  0.16  & -0.08  & -0.18*  &  0.42*** &  \\ 
  day & -0.01  & -0.15  &  0.03  & -0.13  & -0.01  \\ 
   \hline
\end{tabular}
\end{center}
\end{table}

So the question then is how to get this TeX output to a file. Here capture.output() is one friend:

> capture.output(xtable(corstarsl(airquality)), file = "mytable.tex")

Which outputs the code to file named mytable.tex:

$ cat mytable.tex 
% latex table generated in R 2.12.1 by xtable 1.5-6 package
% Mon Feb 21 20:01:03 2011
\begin{table}[ht]
\begin{center}
\begin{tabular}{rlllll}
  \hline
 & ozone & solar.r & wind & temp & month \\ 
  \hline
ozone &  &  &  &  &  \\ 
  solar.r &  0.35*** &  &  &  &  \\ 
  wind & -0.60*** & -0.06  &  &  &  \\ 
  temp &  0.70*** &  0.28*** & -0.46*** &  &  \\ 
  month &  0.16  & -0.08  & -0.18*  &  0.42*** &  \\ 
  day & -0.01  & -0.15  &  0.03  & -0.13  & -0.01  \\ 
   \hline
\end{tabular}
\    end{center}
\end{table}

For "plain" delimited text output, perhaps to dump into a word processor or Spreadsheet, try write.table(), eg:

> write.table(corstarsl(airquality), file = "mytable2.txt")

Which results in a file like this:

$ cat mytable2.txt 
"ozone" "solar.r" "wind" "temp" "month"
"ozone" "" "" "" "" ""
"solar.r" " 0.35***" "" "" "" ""
"wind" "-0.60***" "-0.06 " "" "" ""
"temp" " 0.70***" " 0.28***" "-0.46***" "" ""
"month" " 0.16 " "-0.08 " "-0.18* " " 0.42***" ""
"day" "-0.01 " "-0.15 " " 0.03 " "-0.13 " "-0.01 "

You can alter the quoting and delimiter to your heart's content - see ?write.table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文