r - 将结果摘要打印到 R 中的标准输出

标签 r

我遇到了困难,并且相信我错过了一些非常简单的东西。

我有一个列表,其中包含多个 wilcoxon 测试的结果(带有 Bonferroni 校正),并且希望使用 multcomp 生成一个与 Dunnett 测试的输出类似的表格(即,没有行号显示且间隔良好)。

Example Table

当我将其打印为数据框时,会显示行号,并且列中的文本值右对齐。

该列表的创建者:

for (i in 2:length(split.set)) {
  wrs.mod <- suppressWarnings(wilcox.test(split.set[[1]]$VALUE, split.set[[i]]$VALUE))
  stn.results[i - 1] <- as.character(unique(split.set[[i]]$TREATMENT))
  stat.results[i - 1] <- as.numeric(wrs.mod$statistic)
  p.results[i - 1] <- signif(wrs.mod$p.value, 3)
  if (wrs.mod$p.value < 0.05/(length(split.set) - 1)) sig.results[i - 1] <- "*" else sig.results[i - 1] <- NA
}
wrs.results <- list(Treatment = stn.results, Statistic = stat.results, p = p.results, Significant = sig.results)

如何将其格式化为美观的表格以供打印?

最佳答案

不要将其格式化为列表,而是将其格式化为data.frame并打印:

wrs.results <- data.frame(Treatment = stn.results, Statistic = stat.results, Pvalue = p.results, Significant = sig.results)
print(wrs.results)

您可以通过多种方式自定义数据框的结构(以及外观)。您可能更喜欢将行名称作为处理方式:

wrs.results <- data.frame(row.names = stn.results, Statistic = stat.results, Pvalue = p.results, Significant = sig.results)

或自定义列名称:

colnames(wrs.results) = c("Treatment", "Statistic", "P(>|t|)", "Significance")

关于r - 将结果摘要打印到 R 中的标准输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10983999/

相关文章:

r - 如何使用 knitr 生成 GitHub 风格的 Markdown 文件?

r - 将列添加到 R 摘要

r - 如何组合基于两列的两个数据框?

从 ggplot 图例中删除单个标签

r - 绘制时如何在 R 中隐藏 TclTk 窗口

r - 编写读取示例文件的 R 包小插图?

r - 选择时间序列中的最后 n 个项目

r - 如何使用 ggplot2 绘制 FDA 对象?

r - 从数据框转换为数据表时,head(..) 出现错误

r - 源文件到 R