【问题标题】:R output without [1], how to nicely format?没有[1]的R输出,如何很好地格式化?
【发布时间】:2012-10-18 01:27:13
【问题描述】:

我知道已经发布了一些东西,但没有我要找的那么完整。

使用任何帮助函数(即?mean),并意识到它是输出(或者至少应该能够以相同的方式生成输出)。

你如何进入,对齐/意图?

例子:

strings <- c("t", "df", "p-value", "mean of x", "mean of y")
values  <- c(t, df, pvalue, mean1, mean2)

如果这是您想要在 R 中输出的内容(当从函数调用时),您如何使 [1] 消失,并使值对齐?

【问题讨论】:

    标签: r formatting output


    【解决方案1】:

    这个比较初级,请咨询An Introduction to R以及

    • help(cat)
    • help(sprintf)
    • help(format)

    还有更多。请参阅格式化函数中的(实际上是数千个)示例。这是我的一个包中的一个简单示例:

    print.summary.fastLm <- function(x, ...) {
        cat("\nCall:\n")
        print(x$call)
        cat("\nResiduals:\n")
        print(x$residSum)
        cat("\n")
    
        printCoefmat(x$coefficients, P.values=TRUE, has.Pvalue=TRUE)
        digits <- max(3, getOption("digits") - 3)
        cat("\nResidual standard error: ", formatC(x$sigma, digits=digits), " on ",
            formatC(x$df), " degrees of freedom\n", sep="")
        cat("Multiple R-squared: ", formatC(x$r.squared, digits=digits),
            ",\tAdjusted R-squared: ",formatC(x$adj.r.squared, digits=digits),
            "\n", sep="")
        invisible(x)
    }
    

    【讨论】:

      猜你喜欢
      • 2011-04-13
      • 2019-02-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-15
      相关资源
      最近更新 更多