从R到LaTeX的茎叶 [英] Stem-and-Leaf from R into LaTeX

查看:98
本文介绍了从R到LaTeX的茎叶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是高中统计老师,很抱歉这个简单的问题(或者可能不是那么简单).

High school statistics teacher here, so sorry for the simple question (or maybe not so simple).

我正在运行R创建一个茎叶图.我正在尝试将stem()的茎叶输出转换为LaTeX.这是到目前为止我得到的:

I'm running R to create a stem-and-leaf plot. I'm trying to turn a stem-and-leaf output from stem() into LaTeX. Here is what I've got so far:

y<- c(50, 26, 31, 57, 19, 24, 22, 23, 38, 13, 50, 13, 34, 23, 30, 49, 13, 15, 51)
stem(y)

我试图这样使用xtables(因为它适用于我的简单双向表):

I've tried to use xtables (because it works for my simple two-way tables) as such:

print(xtable(stem(y)), type="latex", latex.environments=c("center"), tabular.environment =    "tabular", NA.string = "")

我得到这个错误:

Error in UseMethod("xtable") : no applicable method for 'xtable' applied to an object of class "NULL"

我尝试了这些选项的变体,但是得到了相似的结果.据我所知,stem()的输出不是数据帧或矩阵,因此xtables不喜欢它.我尝试使用as.data.frame()和as.matrix()将其更改为数据框/矩阵,但没有成功.任何帮助,将不胜感激.我已经运行了一些Google搜索,但没有得到有用的结果,并通过stackoverflow网站进行了调查.任何帮助将不胜感激.

I've tried variations on the the options, but get similar results. From what I can figure, the output from stem() isn't a data frame or matrix, so xtables doesn't like it. I tried changing it to a data frame/matrix using as.data.frame() and as.matrix() but with no success. Any help would be appreciated. I've run a few google searches with no useful results and looked through the stackoverflow site. Any help would be appreciated.

推荐答案

我假设您只是想将结果导出到乳胶中,对吗?

I am assuming that you just want to export the result to latex, am I right?

您可能想尝试以下通过测试的Sweave代码:

You might want to try the following Sweave code, which passed the test:

\documentclass{article}

\usepackage{listings}

\begin{document}

\begin{lstlisting}
<<echo=F, results=tex>>=
y<- c(50, 26, 31, 57, 19, 24, 22, 23, 38, 13, 50, 13, 34, 23, 30, 49, 13, 15, 51)
stem(y)
@ 
\end{lstlisting}

\end{document}

这篇关于从R到LaTeX的茎叶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆