如何从 R 生成报告质量表?

发布于 2024-08-05 05:44:22 字数 655 浏览 13 评论 0原文

如果我有以下称为结果的数据框,

> result
     Name       CV      LCB       UCB
1  within 2.768443 1.869964  5.303702
2 between 4.733483 2.123816 18.551051
3   total 5.483625 3.590745 18.772389

> dput(result,"")
structure(list(Name = structure(c("within", "between", "total"
), .rk.invalid.fields = list(), .Label = character(0)), CV = c(2.768443, 
4.733483, 5.483625), LCB = c(1.869964, 2.123816, 3.590745), UCB = c(5.303702, 
18.551051, 18.772389)), .Names = c("Name", "CV", "LCB", "UCB"
), row.names = c(NA, 3L), class = "data.frame")

那么很好地呈现此数据的最佳方式是什么?理想情况下,我想要一个可以粘贴到报告中的图像文件,或者可能是一个代表表格的 HTML 文件?

设置有效数字的额外积分。

If I have the following dataframe called result

> result
     Name       CV      LCB       UCB
1  within 2.768443 1.869964  5.303702
2 between 4.733483 2.123816 18.551051
3   total 5.483625 3.590745 18.772389

> dput(result,"")
structure(list(Name = structure(c("within", "between", "total"
), .rk.invalid.fields = list(), .Label = character(0)), CV = c(2.768443, 
4.733483, 5.483625), LCB = c(1.869964, 2.123816, 3.590745), UCB = c(5.303702, 
18.551051, 18.772389)), .Names = c("Name", "CV", "LCB", "UCB"
), row.names = c(NA, 3L), class = "data.frame")

What is the best way to present this data nicely? Ideally I'd like an image file that can be pasted into a report, or possibly an HTML file to represent the table?

Extra points for setting number of significant figures.

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

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

发布评论

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

评论(4

↘人皮目录ツ 2024-08-12 05:44:22

我会使用xtable。我通常将它与 Sweave 一起使用。

library(xtable)
d <- data.frame(letter=LETTERS, index=rnorm(52)) 
d.table <- xtable(d[1:5,])
print(d.table,type="html")

如果你想在 Sweave 文档中使用它,你可以像这样使用它:

<<label=tab1,echo=FALSE,results=tex>>=
xtable(d, caption = "Here is my caption", label = "tab:one",caption.placement = "top")
@

I would use xtable. I usually use it with Sweave.

library(xtable)
d <- data.frame(letter=LETTERS, index=rnorm(52)) 
d.table <- xtable(d[1:5,])
print(d.table,type="html")

If you want to use it in a Sweave document, you would use it like so:

<<label=tab1,echo=FALSE,results=tex>>=
xtable(d, caption = "Here is my caption", label = "tab:one",caption.placement = "top")
@
绮烟 2024-08-12 05:44:22

对于表格方面, xtable 包是这样的它可以生成 LaTeX 输出(您可以通过 Sweave 将其用于专业报告)以及 html。

如果您将 Sweave 中的内容与精美的图表结合起来(请参阅有关 ggplot 示例的其他问题),那么您就快完成了。

For the table aspect, the xtable package comes to mind as it can produce LaTeX output (which you can use via Sweave for professional reports) as well as html.

If you combine that in Sweave with fancy graphs (see other questions for ggplot examples) you are almost there.

情绪操控生活 2024-08-12 05:44:22
library(ggplot2)
ggplot(result, aes(x = Name, y = CV, ymin = LCB, ymax = UCB)) + geom_errorbar() + geom_point()
ggplot(result, aes(x = Name, y = CV, ymin = LCB, ymax = UCB)) + geom_pointrange()
library(ggplot2)
ggplot(result, aes(x = Name, y = CV, ymin = LCB, ymax = UCB)) + geom_errorbar() + geom_point()
ggplot(result, aes(x = Name, y = CV, ymin = LCB, ymax = UCB)) + geom_pointrange()
回梦 2024-08-12 05:44:22

要设置有效数字,最简单的方法(请注意,对于此示例数据)是将 Name 移动到 rowname 并对整个内容进行舍入。

#Set the rownames equal to Name - assuming all unique
rownames(result) <- result$Name  
#Drop the Name column so that round() can coerce
#result.mat to a matrix
result.mat <- result[ , -1]       
round(result.mat, 2) #Where 2 = however many sig digits you want.            

这不是一个非常强大的解决方案 - 我认为非唯一的名称值会破坏它,就像其他非数字列一样。但对于生成像您的示例这样的表格,它就可以了。

To set the significant figures, the easiest thing to do (for this sample data, mind you) would be to move Name to rownames and round the whole thing.

#Set the rownames equal to Name - assuming all unique
rownames(result) <- result$Name  
#Drop the Name column so that round() can coerce
#result.mat to a matrix
result.mat <- result[ , -1]       
round(result.mat, 2) #Where 2 = however many sig digits you want.            

This is not a terribly robust solution - non-unique Name values would break it, I think, as would other non-numeric columns. But for producing a table like your example, it does the trick.

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