R output without [1], how to nicely format?

后端 未结 1 1714
滥情空心
滥情空心 2020-12-09 19:26

I know stuff has been posted, but not as complete as what I am looking for.

Take any help function (i.e. ?mean), and realise that it\'s output (or at le

相关标签:
1条回答
  • 2020-12-09 19:36

    This is rather elementary, please consult An Introduction to R as well as

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

    and many more. See the (literally thousands) of examples in formatting functions. Here is a simple example from one of my packages:

    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)
    }
    
    0 讨论(0)
提交回复
热议问题