gpt4 book ai didi

r - 从 R 到 LaTeX 的 Stem-and-Leaf

转载 作者:行者123 更新时间:2023-12-04 11:18:06 24 4
gpt4 key购买 nike

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

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

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

我尝试过使用 xtables(因为它适用于我的简单的双向表):

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() 将其更改为数据框/矩阵,但没有成功。任何帮助,将不胜感激。我运行了一些谷歌搜索,但没有任何有用的结果,并浏览了 stackoverflow 网站。任何帮助将不胜感激。

最佳答案

大量借鉴@DWin 提供的解决方案:

您可以使用 capture.output 捕获 print 语句的输出,并使用 HMisc 包中的 latexTranslate 将其转换为 Latex :

library(Hmisc)
latexTranslate(capture.output(stem(y)))

[1] ""
[2] " The decimal point is 1 digit(s) to the right of the $|$"
[3] ""
[4] " 1 $|$ 33359"
[5] " 2 $|$ 23346"
[6] " 3 $|$ 0148"
[7] " 4 $|$ 9"
[8] " 5 $|$ 0017"
[9] ""

关于r - 从 R 到 LaTeX 的 Stem-and-Leaf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7328354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com