没有[1]的R输出,如何很好地格式化? [英] R output without [1], how to nicely format?

查看:17
本文介绍了没有[1]的R输出,如何很好地格式化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

Take any help function (i.e. ?mean), and realise that it's output (or at least output should be able to be generated in the same manner).

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

How do you get enters, alignment/intendation?

例子:

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

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

If this would be the things you'd want to output in R (when called from a function), how do you make the [1] disappear, and the values lined up?

推荐答案

这个比较初级,请参考R 简介 以及

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

  • 帮助(猫)
  • 帮助(sprintf)
  • 帮助(格式)

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

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("
Call:
")
    print(x$call)
    cat("
Residuals:
")
    print(x$residSum)
    cat("
")

    printCoefmat(x$coefficients, P.values=TRUE, has.Pvalue=TRUE)
    digits <- max(3, getOption("digits") - 3)
    cat("
Residual standard error: ", formatC(x$sigma, digits=digits), " on ",
        formatC(x$df), " degrees of freedom
", sep="")
    cat("Multiple R-squared: ", formatC(x$r.squared, digits=digits),
        ",	Adjusted R-squared: ",formatC(x$adj.r.squared, digits=digits),
        "
", sep="")
    invisible(x)
}

这篇关于没有[1]的R输出,如何很好地格式化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆